Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fireduck64 committed Oct 3, 2018
1 parent 83c8277 commit d29a471
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
14 changes: 13 additions & 1 deletion src/CertGen.java
Expand Up @@ -39,6 +39,8 @@
import snowblossom.proto.WalletDatabase;
import snowblossom.proto.AddressSpec;
import snowblossom.lib.KeyUtil;
import snowblossom.lib.AddressSpecHash;
import snowblossom.lib.AddressUtil;
import snowblossom.client.WalletUtil;
import snowblossom.channels.proto.SignedMessage;
import snowblossom.channels.proto.SignedMessagePayload;
Expand All @@ -59,23 +61,33 @@ public static SslContext getServerSSLContext(WalletDatabase db)
KeyPair tls_pair = KeyUtil.decodeKeypair(tls_wkp);

X509Certificate cert = generateSelfSignedCert(wkp, tls_wkp, address_spec);
System.out.println(cert);

ByteString pem_cert = pemCodeCert(cert);
ByteString pem_prv = pemCodeECPrivateKey(tls_pair.getPrivate());

return GrpcSslContexts.forServer(pem_cert.newInput(), pem_prv.newInput()).build();
}


/**
* @param key_pair Key pair to use to sign the cert inner signed message, the node key
* @param tls_wkp The temporary key to use just for this cert and TLS sessions
* @param spec Address for 'key_pair'
*/
public static X509Certificate generateSelfSignedCert(WalletKeyPair key_pair, WalletKeyPair tls_wkp, AddressSpec spec)
throws Exception
{

AddressSpecHash address_hash = AddressUtil.getHashForSpec(spec);
String address = AddressUtil.getAddressString(ChannelGlobals.ADDRESS_STRING, address_hash);


byte[] encoded_pub= tls_wkp.getPublicKey().toByteArray();
SubjectPublicKeyInfo subjectPublicKeyInfo = new SubjectPublicKeyInfo(
ASN1Sequence.getInstance(encoded_pub));

String dn="CN=Test, O=B";
String dn=String.format("CN=%s, O=SnowChannel", address);
X500Name issuer = new X500Name(dn);
BigInteger serial = BigInteger.valueOf(System.currentTimeMillis());
Date notBefore = new Date(System.currentTimeMillis());
Expand Down
9 changes: 9 additions & 0 deletions src/ChannelGlobals.java
@@ -0,0 +1,9 @@
package snowblossom.channels;

public class ChannelGlobals
{
public static final String ADDRESS_STRING="node";



}
8 changes: 3 additions & 5 deletions src/SnowTrustManagerFactorySpi.java
Expand Up @@ -111,9 +111,10 @@ public void checkServerTrusted(X509Certificate[] chain, String authType)
ASN1Encodable o = parser.readObject();
DEROctetStringParser dero = (DEROctetStringParser) o;
sm = SignedMessage.parseFrom(dero.getOctetStream());


ChannelSigUtil.validateSignedMessage(sm);
SignedMessagePayload payload = SignedMessagePayload.parseFrom(sm.getPayload());
//System.out.println("Payload: " + payload);
address_spec = payload.getClaim();
tls_pub_key = payload.getTlsPublicKey();
}
Expand All @@ -135,12 +136,10 @@ public void checkServerTrusted(X509Certificate[] chain, String authType)
throw new CertificateException("Server did not claim the expected address");
}
}
//if (address_spec.getRequiredSigners() != 1) throw new CertificateException("Multisig not supported for TLS certs");
//if (address_spec.getSigSpecsCount() != 1) throw new CertificateException("Multisig not supported for TLS certs");

try
{

//String algo = SignatureUtil.getAlgo(address_spec.getSigSpecs(0).getSignatureType());
String algo = "RSA";
PublicKey address_key = KeyUtil.decodeKey(tls_pub_key, algo);

Expand All @@ -152,7 +151,6 @@ public void checkServerTrusted(X509Certificate[] chain, String authType)
//System.out.println("Address key: " + HexUtil.getHexString(address_key_bs));
//System.out.println("Cert key: " + HexUtil.getHexString(cert_key_bs));

//if (!address_key.equals(cert.getPublicKey()))
if (!address_key_bs.equals(cert_key_bs))
{
throw new CertificateException("Public key mismatch");
Expand Down
1 change: 0 additions & 1 deletion test/CertGenTest.java
Expand Up @@ -53,7 +53,6 @@ public void testGenAndService()
{
TreeMap<String,String> config_map = new TreeMap<>();
config_map.put("key_count", "1");
//config_map.put("key_mode", "tls");

WalletDatabase db = WalletUtil.makeNewDatabase(new ConfigMem(config_map), new NetworkParamsProd());

Expand Down

0 comments on commit d29a471

Please sign in to comment.