Skip to content

Commit

Permalink
Update to ssh library and bug fixes.
Browse files Browse the repository at this point in the history
* Replaced the ssh library with [sshj](https://github.com/hierynomus/sshj)
    * Adds support for new ssh crypto algorithms
    * Adds support for FIPS compliant algorithms
    * More modern ssh implementation
* Added support for importing and building the library with maven
* Added FindBugs code testing to maven build

This is a major change to the netconf-java library. This version changes how Devices are
created. Instead of passing in parameters in a constructor, Device now uses a Builder. This
allows passing in whichver parameters you need and creating a unique Device object. Once created,
you no longer change change attributes like userName or port. You would need to create a new Device object.

See the Examples/CreateDevice class for examples on how to create a new Device.
  • Loading branch information
Peter Hill committed Jun 25, 2019
1 parent 5d189cb commit e8bf727
Show file tree
Hide file tree
Showing 669 changed files with 11,106 additions and 117,199 deletions.
59 changes: 0 additions & 59 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -28,62 +28,3 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of Juniper Networks.

This software includes work that was released under the following license:

Copyright (c) 2005 - 2006 Swiss Federal Institute of Technology (ETH Zurich),
Department of Computer Science (http://www.inf.ethz.ch),
Christian Plattner. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

a.) Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
b.) Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
c.) Neither the name of ETH Zurich nor the names of its contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

The Java implementations of the AES, Blowfish and 3DES ciphers have been
taken (and slightly modified) from the cryptography package released by
"The Legion Of The Bouncy Castle".

Their license states the following:

Copyright (c) 2000 - 2004 The Legion Of The Bouncy Castle
(http://www.bouncycastle.org)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

85 changes: 25 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,31 @@ partners, and the development community. To report bug-fixes, issues, suggestio
REQUIREMENTS
============

OpenJDK>=1.6.0
[OpenJDK 8](http://openjdk.java.net/projects/jdk8/) or Java 8

Releases
========
Latest .jar file in release section contains netconf-java compiled from Java SE 8u65.
If user wants to use some other java version, then download the source code and compile it with desired version.

v2.0.0
------
* Replaced the ssh library with [JSch](http://www.jcraft.com/jsch/)
* Adds support for new ssh crypto algorithms
* More modern ssh implementation
* Added support for importing and building the library with maven
* Added FindBugs code testing to maven build

This is a breaking change to the API. New Device objects are now created using a builder.
Example:
```
Device device = Device.builder().hostName("hostname")
.userName("username")
.password("password")
.hostKeysFileName("hostKeysFileName")
.build();
```

SYNOPSIS
========

Expand All @@ -35,7 +53,12 @@ SYNOPSIS
ParserConfigurationException, SAXException, IOException {

//Create device
Device device = new Device("hostname","user","password",null);
Device device = Device.builder()
.hostName("hostname")
.userName("username")
.password("password")
.hostKeysFileName("hostKeysFileName")
.build();
device.connect();

//Send RPC and receive RPC Reply as XML
Expand Down Expand Up @@ -71,64 +94,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”

The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of Juniper Networks.

This software includes work that was released under the following license:

Copyright (c) 2005 - 2006 Swiss Federal Institute of Technology (ETH Zurich),
Department of Computer Science (http://www.inf.ethz.ch),
Christian Plattner. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

a.) Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
b.) Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
c.) Neither the name of ETH Zurich nor the names of its contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

The Java implementations of the AES, Blowfish and 3DES ciphers have been
taken (and slightly modified) from the cryptography package released by
"The Legion Of The Bouncy Castle".

Their license states the following:

Copyright (c) 2000 - 2004 The Legion Of The Bouncy Castle
(http://www.bouncycastle.org)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

AUTHOR
======

Expand Down
42 changes: 42 additions & 0 deletions examples/CreateDevice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import net.juniper.netconf.Device;
import net.juniper.netconf.NetconfException;

class CreateDevice {

private static final String HOSTNAME = "HOSTNAME";
private static final String USERNAME = "username";
private static final String PASSWORD = "passwd!";
private static final String PEM_KEY_FILE_PATH = "/tmp/pemFile";


/**
* Create a new Device using username and password authentication.
*
* @return an unconnected Device object.
* @throws NetconfException if there are issues creating the Device.
*/
public static Device createDevice() throws NetconfException {
return Device.builder()
.hostName(HOSTNAME)
.userName(USERNAME)
.password(PASSWORD)
.strictHostKeyChecking(false)
.build();
}

/**
* Create a new Device using username and public key file.
*
* @param keyFile the path to a private key file used to authenticate to the Device.
* @return an unconnected Device object.
* @throws NetconfException if there are issues creating the Device.
*/
public static Device createDeviceWithKeyAuth(String keyFile) throws NetconfException {
return Device.builder()
.hostName(HOSTNAME)
.userName(USERNAME)
.pemKeyFile(PEM_KEY_FILE_PATH)
.strictHostKeyChecking(false)
.build();
}
}
30 changes: 13 additions & 17 deletions examples/EditConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
*
*/

import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import net.juniper.netconf.CommitException;
import net.juniper.netconf.LoadException;
import net.juniper.netconf.NetconfException;
import org.xml.sax.SAXException;

import net.juniper.netconf.Device;
import net.juniper.netconf.LoadException;
import net.juniper.netconf.XML;
import net.juniper.netconf.XMLBuilder;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;


public class EditConfiguration {
public static void main(String[] args) throws LoadException, IOException,
NetconfException, ParserConfigurationException, SAXException {

public static void main(String[] args) throws IOException,
ParserConfigurationException, SAXException {


/*Build the XML configuration
*The XML configuration required is:
*
Expand All @@ -36,9 +36,8 @@ public static void main(String[] args) throws LoadException, IOException,
XMLBuilder builder = new XMLBuilder();
XML ftp_config = builder.createNewConfig("system", "services", "ftp");

//Create the device
Device device = new Device("hostname","user","PaSsWoRd",null);
device.connect();
Device device = CreateDevice.createDevice();
device.connect();

//Lock the configuration first
boolean isLocked = device.lockConfig();
Expand All @@ -51,15 +50,12 @@ public static void main(String[] args) throws LoadException, IOException,
try {
device.loadXMLConfiguration(ftp_config.toString(), "merge");
device.commit();
} catch(LoadException e) {
System.out.println(e.getMessage());
return;
} catch(CommitException e) {
} catch(LoadException | CommitException e) {
System.out.println(e.getMessage());
return;
}

//Unlock the configuration and close the device.
//Unlock the configuration and close the device.
device.unlockConfig();
device.close();
}
Expand Down
17 changes: 7 additions & 10 deletions examples/ShowChassis.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@
*
*/

import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import net.juniper.netconf.NetconfException;
import net.juniper.netconf.Device;
import net.juniper.netconf.XML;
import org.xml.sax.SAXException;

import net.juniper.netconf.XML;
import net.juniper.netconf.Device;
import java.io.IOException;

public class ShowChassis {
public static void main(String args[]) throws NetconfException,
ParserConfigurationException, SAXException, IOException {

//Create device
Device device = new Device("hostname","user","password",null);
public static void main(String[] args) throws
SAXException, IOException {

Device device = CreateDevice.createDevice();
device.connect();

//Send RPC and receive RPC Reply as XML
Expand Down
59 changes: 27 additions & 32 deletions examples/parse_interface_info.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,44 @@

//code to parse layered rpc reply

import java.util.*;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import net.juniper.netconf.CommitException;
import net.juniper.netconf.LoadException;
import net.juniper.netconf.NetconfException;
import org.xml.sax.SAXException;
import net.juniper.netconf.Device;
import net.juniper.netconf.XML;
import net.juniper.netconf.XMLBuilder;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

public class parse_interface_info {
public static void main(String[] args) throws LoadException, IOException,
NetconfException, ParserConfigurationException, SAXException {
Device device = new Device("hostname","username","passwd",null);
device.connect();
public static void main(String[] args) throws IOException,
SAXException {

Device device = CreateDevice.createDevice();
device.connect();

XML rpc_reply = device.executeRPC("get-interface-information");
System.out.println(rpc_reply.toString());
// Obtain a list of list of ‘org.w3c.dom.Node’ objects
List<String> list = Arrays.asList("interface-information","physical-interface");
List physical_interfaces_list = rpc_reply.findNodes(list);
// Print the value for each of the name elements:
Iterator iter = physical_interfaces_list.iterator();
while(iter.hasNext()) {
Node node = (Node)iter.next();
NodeList child_nodes_of_phy_interface = node.getChildNodes();
// child_nodes_of_phy_interface contains nodes like <name> and <admin-status>
// Get each <name> node from the NodeList
for (int i = 0; i < child_nodes_of_phy_interface.getLength(); i++) {
Node child_node = child_nodes_of_phy_interface.item(i);
if (child_node.getNodeType() != Node.ELEMENT_NODE){
continue;
}
if (child_node.getNodeName().equals("name"))
{ // Print the text value of the <name> node
System.out.println(child_node.getTextContent());
}
break;
for (Object o : physical_interfaces_list) {
Node node = (Node) o;
NodeList child_nodes_of_phy_interface = node.getChildNodes();
// child_nodes_of_phy_interface contains nodes like <name> and <admin-status>
// Get each <name> node from the NodeList
for (int i = 0; i < child_nodes_of_phy_interface.getLength(); i++) {
Node child_node = child_nodes_of_phy_interface.item(i);
if (child_node.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
if (child_node.getNodeName().equals("name")) { // Print the text value of the <name> node
System.out.println(child_node.getTextContent());
}
break;
}
}
}
}
}
Loading

0 comments on commit e8bf727

Please sign in to comment.