netopeer2 icon indicating copy to clipboard operation
netopeer2 copied to clipboard

Possible to set TLS version used?

Open mpet opened this issue 1 year ago • 17 comments

Hi,

We want to test our java client using TLS 1.3 and set Netopeer2 to only support TLS 1.2 and check what happens. Is it possible to set a specific version of TLS in Netopeer2?

br,

//mikael

mpet avatar Apr 19 '24 08:04 mpet

You can configure this leaf-list with only the versions you want to support. Use libyang tree schema format to see the parents of the node to be able to set it.

michalvasko avatar Apr 19 '24 09:04 michalvasko

So you mean I can do an edit-config as long as the subtree contains the correct parents? How can I query for the parents of the node? Run something on command line ? I am not sure I understand.

mpet avatar May 17 '24 08:05 mpet

Never mind, I may have only confused you. Yes, you can send an edit-config and change the configuration to adjust the supported TLS versions.

michalvasko avatar May 20 '24 07:05 michalvasko

I checked the following:

For 4.1.2.1. The "tls-server-grouping" Grouping

From the comment I read:

The "hello-params" node, which must be enabled by a feature, configures parameters for the TLS sessions established by this configuration.

The feature to enable is "tls-server-hello-params-config"

I checked the hello message from the server:

<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
  <capabilities>
    <capability>urn:ietf:params:netconf:base:1.0</capability>
    <capability>urn:ietf:params:netconf:base:1.1</capability>
    <capability>urn:ietf:params:netconf:capability:writable-running:1.0</capability>
    <capability>urn:ietf:params:netconf:capability:candidate:1.0</capability>
    <capability>urn:ietf:params:netconf:capability:rollback-on-error:1.0</capability>
    <capability>urn:ietf:params:netconf:capability:validate:1.1</capability>
    <capability>urn:ietf:params:netconf:capability:startup:1.0</capability>
    <capability>urn:ietf:params:netconf:capability:xpath:1.0</capability>
    <capability>urn:ietf:params:netconf:capability:with-defaults:1.0?basic-mode=explicit&amp;also-supported=report-all,report-all-tagged,trim,explicit</capability><capability>urn:ietf:params:netconf:capability:notification:1.0</capability>
    <capability>urn:ietf:params:netconf:capability:interleave:1.0</capability>
    <capability>urn:ietf:params:xml:ns:yang:ietf-yang-metadata?module=ietf-yang-metadata&amp;revision=2016-08-05</capability>
    <capability>urn:ietf:params:xml:ns:yang:1?module=yang&amp;revision=2017-02-20</capability>
    <capability>urn:ietf:params:xml:ns:yang:ietf-inet-types?module=ietf-inet-types&amp;revision=2013-07-15</capability>
    <capability>urn:ietf:params:xml:ns:yang:ietf-yang-types?module=ietf-yang-types&amp;revision=2013-07-15</capability>
    <capability>urn:ietf:params:netconf:capability:yang-library:1.1?revision=2019-01-04&amp;content-id=32</capability>
    <capability>urn:sysrepo:plugind?module=sysrepo-plugind&amp;revision=2020-12-10</capability>
    <capability>urn:ietf:params:xml:ns:yang:ietf-netconf-acm?module=ietf-netconf-acm&amp;revision=2018-02-14</capability>
    <capability>urn:ietf:params:xml:ns:netconf:base:1.0?module=ietf-netconf&amp;revision=2013-09-29&amp;features=writable-running,candidate,rollback-on-error,validate,startup,url,xpath</capability>
    <capability>urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults?module=ietf-netconf-with-defaults&amp;revision=2011-06-01</capability>
    <capability>urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?module=ietf-netconf-notifications&amp;revision=2012-02-06</capability>
    <capability>urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring?module=ietf-netconf-monitoring&amp;revision=2010-10-04</capability>
    <capability>urn:ietf:params:xml:ns:netconf:notification:1.0?module=notifications&amp;revision=2008-07-14</capability>
    <capability>urn:ietf:params:xml:ns:netmod:notification?module=nc-notifications&amp;revision=2008-07-14</capability>
    <capability>urn:ietf:params:xml:ns:yang:ietf-x509-cert-to-name?module=ietf-x509-cert-to-name&amp;revision=2014-12-10</capability>
    <capability>urn:ietf:params:xml:ns:yang:iana-crypt-hash?module=iana-crypt-hash&amp;revision=2014-08-06</capability>
  </capabilities>
  <session-id>2</session-id>
</hello>

I cannot see it in the hello message. Is it not supported?

I have also tried the following edit-config

                  <netconf-server xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-server" >
                    <listen>
                        <endpoint>
                            <name>default-tls</name>
                            <tls>
                                <tls-server-parameters>
                                        <tls-versions xmlns="urn:ietf:params:xml:ns:yang:ietf-tls-common" xmlns:tlscmn="urn:ietf:params:xml:ns:yang:ietf-tls-common">
                                            <tls-version>tlscmn:tls-1.2</tls-version>
                                        </tls-versions>
                                </tls-server-parameters>
                            </tls>
                        </endpoint>
                    </listen>
                </netconf-server>

But the only thing I get is an error code like:

<rpc-reply message-id="5" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
   <rpc-error>
     <error-type>application</error-type>
     <error-tag>operation-failed</error-tag>
     <error-severity>error</error-severity>
     <error-path>/ietf-netconf-server:netconf-server/listen/endpoint[name='default-tls']/tls/tls-server-parameters</error-path>
     <error-message xml:lang="en">Unknown element "tls-versions".</error-message>
   </rpc-error>
 </rpc-reply>

Any ideas what I am missing?

//mike

mpet avatar May 22 '24 14:05 mpet

It seems you are not using the current libnetconf2 version and you have a bit older YANG modules with different node structure, which confuses me and I cannot really help. But TLS version configuration should be supported.

michalvasko avatar May 23 '24 08:05 michalvasko

Hi

I am using the following when building in docker:

libyang

61 62 RUN
63 cd /opt/dev &&
64 git clone https://github.com/CESNET/libyang.git && cd libyang && git checkout libyang1 &&
65 mkdir build && cd build &&
66 cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE="Release" .. &&
67 make -j2 &&
68 make install 69 70 # sysrepo 71 RUN
72 cd /opt/dev &&
73 git clone https://github.com/sysrepo/sysrepo.git && cd sysrepo && git checkout libyang1 &&
74 mkdir build && cd build &&
75 cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE="Release" .. &&
76 make -j2 &&
77 make install 78 79 # libssh 80 RUN
81 cd /opt/dev &&
82 git clone https://git.libssh.org/projects/libssh.git && cd libssh && git checkout stable-0.9 &&
83 mkdir build && cd build &&
84 cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE="Release" -DWITH_ZLIB=ON -DWITH_NACL=OFF -DWITH_PCAP=OFF .. &&
85 make -j2 &&
86 make install 87 88 # libnetconf2 (latest package is not available on Ubuntu 18.04, so we have to compile it from source) 89 RUN
90 cd /opt/dev &&
91 git clone https://github.com/CESNET/libnetconf2.git && cd libnetconf2 &&
92 git checkout libyang1 &&
93 mkdir build && cd build &&
94 cmake -DCMAKE_BUILD_TYPE:String="Release" -DCMAKE_INSTALL_PREFIX:PATH=/usr -DENABLE_BUILD_TESTS=OFF .. &&
95 make -j2 &&
96 make install 97 98 # netopeer 2 (latest package is not available on Ubuntu 18.04, so we have to compile it from source) 99 RUN
100 cd /opt/dev &&
101 git clone https://github.com/CESNET/Netopeer2.git && cd Netopeer2 &&
102 git checkout libyang1 &&
103 mkdir build && cd build &&
104 cmake -DNACM_RECOVERY_UID=102 -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_BUILD_TYPE:String="Release" .. &&
105 make -j2 &&
106 make install

mpet avatar May 27 '24 11:05 mpet

Okay, I cannot help you with libyang1 versions, that is not supported for a long time.

michalvasko avatar May 27 '24 14:05 michalvasko

I guess my build was old. Is this the correct place to look for versions and libnames? https://github.com/CESNET/netopeer2/blob/master/CMakeLists.txt

mpet avatar May 28 '24 06:05 mpet

Yes, master branch should be fine, but you can also use devel for the most up-to-date version.

michalvasko avatar May 28 '24 06:05 michalvasko

Hi

I tried devel for all except for

When making libyang on 'devel' I got:

2024-05-28 09:24:23,743 (Wire.java:92) DEBUG : http-outgoing-0 << "{"stream":"\u001b[91mCMake Error at /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:137 (message):\n Could NOT find PCRE2 (missing: PCRE2_LIBRARY PCRE2_INCLUDE_DIR) (Required\n is at least version "10.21")\nCall Stack (most recent call first):\n /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)\n CMakeModules/FindPCRE2.cmake:63 (find_package_handle_standard_args)\n CMakeLists.txt:409 (find_package)\n\n\u001b[0m"}[\r][\n]" 2024-05-28 09:24:23,743 (Wire.java:92) DEBUG : http-outgoing-0 << "[\r][\n]" 2024-05-28 09:24:23,743 (BuildImageResultCallback.java:34) DEBUG : BuildResponseItem() 2024-05-28 09:24:23,743 (ImageFromDockerfile.java:106) DEBUG : CMake Error at /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:137 (message):

What am I lacking?

Also I used cd libssh && git checkout stable-0.9 is there a more recent version you use?

These questions are not really related to my original question. I can open a new question if you want.

mpet avatar May 28 '24 07:05 mpet

What am I lacking?

Could NOT find PCRE2

The error is written right there, what are you asking me exactly?

michalvasko avatar May 28 '24 07:05 michalvasko

Yes I guess it was a dumb question :-) I was not aware of such a library but after some googling I found something called pcre2-dev so I assume it is the correct one.

mpet avatar May 28 '24 11:05 mpet

Yes, that package should be the right one. Requirements of each library are also mentioned in their README. And to answer your previous question about libssh, I always use the latest release, currently 0.10.6.

michalvasko avatar May 28 '24 11:05 michalvasko

@michalvasko you don't happen to have a code snippet on how to make openssl?

mpet avatar May 30 '24 04:05 mpet

You mean how to compile it? It is using cmake, so just like any other cmake projects except you may need to provide some options. Those depend a lot on your exact environment and build system so I cannot help with that.

michalvasko avatar May 30 '24 06:05 michalvasko

@michalvasko which options do you use and for which distro?

mpet avatar May 30 '24 10:05 mpet

I cannot share those publicly and it is not for Linux anyway, so no distro.

michalvasko avatar May 30 '24 10:05 michalvasko

I managed to build a new docker image for Netopeer2 but when I run it I get this error:

Caused by: com.github.dockerjava.api.exception.BadRequestException: Status 400: {"message":"failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/usr/bin/netopeer2-server": stat /usr/bin/netopeer2-server: no such file or directory: unknown"}

Previously I built it using:

RUN
cd /opt/dev &&
git clone https://github.com/CESNET/Netopeer2.git && cd Netopeer2 &&
git checkout libyang1 &&
mkdir build && cd build &&
cmake -DNACM_RECOVERY_UID=102 -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_BUILD_TYPE:String="Release" .. &&
make -j2 &&
make install

I used this now for netopeer2:

RUN
cd /opt/dev &&
git clone https://github.com/CESNET/Netopeer2.git && cd Netopeer2 &&
git checkout tags/v2.2.28 &&
mkdir build && cd build &&
cmake -DNACM_RECOVERY_UID=102 -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_BUILD_TYPE:String="Release" .. &&
make -j2 &&
make install

What am I missing?

br,

//Mikael

mpet avatar Aug 21 '24 05:08 mpet

You are using an obsolete version that we do not provide support for anymore. But the server was obviously installed in some other path, not sure why.

michalvasko avatar Aug 21 '24 06:08 michalvasko

@michalvasko git checkout tags/v2.2.28 not valid?!

I checked the latest release is https://github.com/CESNET/netopeer2/releases/tag/v2.2.28

mpet avatar Aug 21 '24 06:08 mpet

Oh, sorry, I went though it too quickly and misunderstood. Then the problem is likely due to the server being installed in /usr/sbin/netopeer2-server.

michalvasko avatar Aug 21 '24 07:08 michalvasko

ok the sbin seems to work. When I start the netopeer2 from container with

CMD ["/usr/sbin/netopeer2-server", "-d", "-v2 3"]

I can see the following:

[INF]: SR: Datastore copied from to . [INF]: SR: Connection 1 created. [INF]: SR: Session 1 (user "root", CID 1) created. [INF]: SR: Triggering "ietf-netconf-server" "done" event on enabled data. [INF]: LN: Listening on 0.0.0.0:830 for SSH connections. [INF]: SR: Triggering "ietf-keystore" "done" event on enabled data. [INF]: SR: Triggering "ietf-truststore" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-acm" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-acm" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-acm" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-acm" "done" event on enabled data.

I compared this to my previous built netopeer2 running with the same command above.

[INF]: LY: Resolving "ietf-netconf-server" unresolved schema nodes and their constraints... [INF]: LY: All "ietf-netconf-server" schema nodes and constraints resolved. [INF]: LY: Module "ietf-netconf-server@2019-07-02" successfully parsed as implemented. [INF]: SR: No scheduled changes. [INF]: SR: Datastore copied from to . [INF]: SR: Connection 1 created. [INF]: SR: Session 1 (user "root", CID 1) created. [INF]: LY: Resolving unresolved data nodes and their constraints... [INF]: LY: All data nodes and constraints resolved. [INF]: SR: Triggering "ietf-netconf-server" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-server" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-server" "done" event on enabled data. [INF]: LN: Listening on 0.0.0.0:830 for SSH connections. [INF]: SR: Triggering "ietf-netconf-server" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-server" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-server" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-server" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-server" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-server" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-server" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-server" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-server" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-server" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-server" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-server" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-server" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-server" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-server" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-server" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-server" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-server" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-server" "done" event on enabled data. [INF]: SR: Triggering "ietf-keystore" "done" event on enabled data. [INF]: SR: Triggering "ietf-truststore" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-acm" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-acm" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-acm" "done" event on enabled data. [INF]: SR: Triggering "ietf-netconf-acm" "done" event on enabled data.

Not sure what I am failing in my changed newly built I seem to lack output.

Do you know why I am missing messages ? Less logs in new or am I lacking something.

mpet avatar Aug 21 '24 10:08 mpet

I am sorry, but please do not ask such generic and redundant questions. There were lots of changes compared to the previous version you were using, which includes different messages and changed configuration processing. Create an issue if you encounter an actual problem.

michalvasko avatar Aug 21 '24 11:08 michalvasko

ok let me rephrase it:

In our Ubuntu based docker file we create the 'netconf' user with password 'netconf' it is not so secret :) Then we generate the keys i .ssh `Adding netconf user RUN adduser --system netconf RUN mkdir -p /home/netconf/.ssh RUN echo "netconf:netconf" | chpasswd && adduser netconf sudo

Clearing and setting authorized ssh keys RUN
echo '' > /home/netconf/.ssh/authorized_keys &&
ssh-keygen -A &&
ssh-keygen -t rsa -b 4096 -P '' -f /home/netconf/.ssh/id_rsa &&
cat /home/netconf/.ssh/id_rsa.pub >> /home/netconf/.ssh/authorized_keys`

However when I run my netopeer2 now with our client I get this message when we try to connect.

"Caused by: com.company.exceptions.AuthenticationException: Authentication failure, Could be because no public key file was found, Server could use a different way to authenticate users available authentication methods is: publickey, Server version: SSH-2.0-libssh_0.11.0

Has the location of the key changed? Where is is located now?

mpet avatar Aug 22 '24 15:08 mpet

To use these SSH keys, they need to be configured for both the server and the client. You likely know how to set it for client, that has not changed for a long time, but in the server you need to configure it based on example_configuration/ssh_listen.xml. That should also be the default after running make install for netopeer2, but only after the steps you posted (so you should have them before netopeer2 installation, not after).

michalvasko avatar Aug 23 '24 05:08 michalvasko

ok so I need to modify the ssh-listen.xml and select one of the methods ( key/password/keyboard interactive) to authenticate. Is it the sysrepocfg and an import I need to do? Which is the --module ?

mpet avatar Aug 23 '24 07:08 mpet

The exact same listen configuration will get you the behavior you want. public-keys container enables the publickey SSH authentication method and use-system-keys will load them for every user from ~/.ssh/authorized_keys instead of having to manually import them into the configuration. You can import ssh_listen.ssh but you will want to change the user user to an actual user you want to authenticate as. Import using sysrepocfg -I <file> -m ietf-netconf-server or edit using a text editor sysrepocfg -E <text-editor (vim)> -m ietf-netconf-server.

michalvasko avatar Aug 23 '24 08:08 michalvasko

We also tested 'keyboard-interactive' auth before and we could see that it was supported:

2024-08-23 10:55:52,192 (ImplSsh.java:386) DEBUG : Available authentication methods: [publickey, keyboard-interactive, password]

We could see that when public key failed it tried 'keyboard-interactive'

2024-08-23 10:55:53,073 (ImplSsh.java:398) DEBUG : Trying to authenticate with method: keyboard-interactive 2024-08-23 10:55:53,171 (Wire.java:92) DEBUG : http-outgoing-3 << "58[\r][\n]" 2024-08-23 10:55:53,171 (Wire.java:92) DEBUG : http-outgoing-3 << "[0x2][0x0][0x0][0x0][0x0][0x0][0x0]P[INF]: LN: Received an SSH message "request-service" of subtype "ssh-userauth".[\n]" 2024-08-23 10:55:53,171 (Wire.java:92) DEBUG : http-outgoing-3 << "[\r][\n]" 2024-08-23 10:55:53,171 (Slf4jLogConsumer.java:73) INFO : STDERR: [INF]: LN: Received an SSH message "request-service" of subtype "ssh-userauth". 2024-08-23 10:55:53,171 (Wire.java:92) DEBUG : http-outgoing-3 << "4d[\r][\n]" 2024-08-23 10:55:53,171 (Wire.java:92) DEBUG : http-outgoing-3 << "[0x2][0x0][0x0][0x0][0x0][0x0][0x0]E[INF]: LN: Received an SSH message "request-auth" of subtype "none".[\n]" 2024-08-23 10:55:53,171 (Wire.java:92) DEBUG : http-outgoing-3 << "[\r][\n]" 2024-08-23 10:55:53,171 (Slf4jLogConsumer.java:73) INFO : STDERR: [INF]: LN: Received an SSH message "request-auth" of subtype "none".

Now we only get the public-key support for auth. How to enable that option as a fallback?

mpet avatar Aug 23 '24 09:08 mpet

The recent ietf-netconf-server YANG modules from the relevant RFC drafts do not specify any fallback options. You must explicitly specify the authorized users and then for each the exact authentication method to be authenticated. If you configure several, the user must successfully authenticate by all the methods to be considered fully authenticated.

michalvasko avatar Aug 23 '24 09:08 michalvasko