From 0eb8a6e7e6a045fbf83defd82eb0e424f8d6706f Mon Sep 17 00:00:00 2001 From: Cube Date: Fri, 4 Mar 2016 14:55:04 +0200 Subject: [PATCH] Move RSA keys to their own file RSA keys are sensitive information that should not be stored in git repositories. This commit moves them to their own file, adds it to .gitignore and provides a template file. --- .gitignore | 1 + data/net.xml | 5 ---- data/rsa.xml.dist | 5 ++++ .../main/org/apollo/net/NetworkConstants.java | 25 ++++++++++++------- 4 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 data/rsa.xml.dist diff --git a/.gitignore b/.gitignore index 4e737abd..993de82c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ *.iml /data/fs +/data/rsa.xml /data/savedGames /lib/ */target/ diff --git a/data/net.xml b/data/net.xml index 663d2811..8bd75431 100644 --- a/data/net.xml +++ b/data/net.xml @@ -1,9 +1,4 @@ - - 143690958001225849100503496893758066948984921380482659564113596152800934352119496873386875214251264258425208995167316497331786595942754290983849878549630226741961610780416197036711585670124061149988186026407785250364328460839202438651793652051153157765358767514800252431284681765433239888090564804146588087023 - 124425314960550024206991065332877157931472210939505789558012215720454903710618146200843877022273818555405810618059191162604008259757866640421952188957253368398733319663236323097864278319463888334484786055755767881706264786840339899269810859874287402892848784247637729987603089254067178011764721326471352835473 - - 80 43594 diff --git a/data/rsa.xml.dist b/data/rsa.xml.dist new file mode 100644 index 00000000..22506b24 --- /dev/null +++ b/data/rsa.xml.dist @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/net/src/main/org/apollo/net/NetworkConstants.java b/net/src/main/org/apollo/net/NetworkConstants.java index 2be775f3..e16345f7 100644 --- a/net/src/main/org/apollo/net/NetworkConstants.java +++ b/net/src/main/org/apollo/net/NetworkConstants.java @@ -55,15 +55,6 @@ public final class NetworkConstants { throw new IOException("Root node name is not 'net'."); } - XmlNode rsa = net.getChild("rsa"); - Preconditions.checkState(rsa != null, "Root node must have a child named 'rsa'."); - - XmlNode modulus = rsa.getChild("modulus"), exponent = rsa.getChild("private-exponent"); - Preconditions.checkState(modulus != null && exponent != null, "Rsa node must have two children: 'modulus' and 'private-exponent'."); - - RSA_MODULUS = new BigInteger(modulus.getValue()); - RSA_EXPONENT = new BigInteger(exponent.getValue()); - XmlNode ports = net.getChild("ports"); Preconditions.checkState(ports != null, "Root node must have a child named 'ports'."); @@ -76,6 +67,22 @@ public final class NetworkConstants { } catch (Exception exception) { throw new ExceptionInInitializerError(new IOException("Error parsing net.xml.", exception)); } + + try (InputStream is = new FileInputStream("data/rsa.xml")) { + XmlNode rsa = new XmlParser().parse(is); + if (!rsa.getName().equals("rsa")) { + throw new IOException("Root node name is not 'rsa'."); + } + + XmlNode modulus = rsa.getChild("modulus"), exponent = rsa.getChild("private-exponent"); + Preconditions.checkState(modulus != null && exponent != null, "Rsa node must have two children: 'modulus' and 'private-exponent'."); + + Preconditions.checkState(modulus.getValue() != null && exponent.getValue() != null, "Value missing for 'modulus' or 'private-exponent'"); + RSA_MODULUS = new BigInteger(modulus.getValue()); + RSA_EXPONENT = new BigInteger(exponent.getValue()); + } catch (Exception exception) { + throw new ExceptionInInitializerError(new IOException("Error parsing rsa.xml", exception)); + } } /**