From 7fdfb5cf12c68072b5dac1de6680dce7ac9f16b4 Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Fri, 29 Jan 2016 02:23:14 +0000
Subject: [PATCH] Put the OID in SigType

---
 .../net/i2p/crypto/SelfSignedGenerator.java   | 24 +-------------
 core/java/src/net/i2p/crypto/SigType.java     | 31 +++++++++++++------
 2 files changed, 22 insertions(+), 33 deletions(-)

diff --git a/core/java/src/net/i2p/crypto/SelfSignedGenerator.java b/core/java/src/net/i2p/crypto/SelfSignedGenerator.java
index 95c5ee08b3..4418755fcb 100644
--- a/core/java/src/net/i2p/crypto/SelfSignedGenerator.java
+++ b/core/java/src/net/i2p/crypto/SelfSignedGenerator.java
@@ -57,15 +57,6 @@ public final class SelfSignedGenerator {
     private static final String OID_OU = "2.5.4.11";
     // Subject Key Identifier
     private static final String OID_SKI = "2.5.29.14";
-    //private static final String OID_RSA_4096_PUB = "1.2.840.113549.1.1.1";
-    // TODO put these in SigType
-    private static final String OID_DSA_1024_SIG = "1.2.840.10040.4.3";
-    private static final String OID_ECDSA_P256_SIG = "1.2.840.10045.4.3.2";
-    private static final String OID_ECDSA_P384_SIG = "1.2.840.10045.4.3.3";
-    private static final String OID_ECDSA_P521_SIG = "1.2.840.10045.4.3.4";
-    private static final String OID_RSA_2048_SIG = "1.2.840.113549.1.1.11";
-    private static final String OID_RSA_3072_SIG = "1.2.840.113549.1.1.12";
-    private static final String OID_RSA_4096_SIG = "1.2.840.113549.1.1.13";
 
     private static final Map<String, String> OIDS;
     static {
@@ -92,29 +83,16 @@ public final class SelfSignedGenerator {
         PublicKey jpub = SigUtil.toJavaKey(pub);
         PrivateKey jpriv = SigUtil.toJavaKey(priv);
 
-        // TODO just put the oid in the sigtype
         String oid;
         switch (type) {
             case DSA_SHA1:
-                oid = OID_DSA_1024_SIG;
-                break;
             case ECDSA_SHA256_P256:
-                oid = OID_ECDSA_P256_SIG;
-                break;
             case ECDSA_SHA384_P384:
-                oid = OID_ECDSA_P384_SIG;
-                break;
             case ECDSA_SHA512_P521:
-                oid = OID_ECDSA_P521_SIG;
-                break;
             case RSA_SHA256_2048:
-                oid = OID_RSA_2048_SIG;
-                break;
             case RSA_SHA384_3072:
-                oid = OID_RSA_3072_SIG;
-                break;
             case RSA_SHA512_4096:
-                oid = OID_RSA_4096_SIG;
+                oid = type.getOID();
                 break;
             default:
                 throw new GeneralSecurityException("Unsupported: " + type);
diff --git a/core/java/src/net/i2p/crypto/SigType.java b/core/java/src/net/i2p/crypto/SigType.java
index 05dd1906e7..1a3d0646d6 100644
--- a/core/java/src/net/i2p/crypto/SigType.java
+++ b/core/java/src/net/i2p/crypto/SigType.java
@@ -32,20 +32,20 @@ public enum SigType {
      *  Pubkey 128 bytes; privkey 20 bytes; hash 20 bytes; sig 40 bytes
      *  @since 0.9.8
      */
-    DSA_SHA1(0, 128, 20, 20, 40, SigAlgo.DSA, "SHA-1", "SHA1withDSA", CryptoConstants.DSA_SHA1_SPEC, "0"),
+    DSA_SHA1(0, 128, 20, 20, 40, SigAlgo.DSA, "SHA-1", "SHA1withDSA", CryptoConstants.DSA_SHA1_SPEC, "1.2.840.10040.4.3", "0"),
     /**  Pubkey 64 bytes; privkey 32 bytes; hash 32 bytes; sig 64 bytes */
-    ECDSA_SHA256_P256(1, 64, 32, 32, 64, SigAlgo.EC, "SHA-256", "SHA256withECDSA", ECConstants.P256_SPEC, "0.9.12"),
+    ECDSA_SHA256_P256(1, 64, 32, 32, 64, SigAlgo.EC, "SHA-256", "SHA256withECDSA", ECConstants.P256_SPEC, "1.2.840.10045.4.3.2", "0.9.12"),
     /**  Pubkey 96 bytes; privkey 48 bytes; hash 48 bytes; sig 96 bytes */
-    ECDSA_SHA384_P384(2, 96, 48, 48, 96, SigAlgo.EC, "SHA-384", "SHA384withECDSA", ECConstants.P384_SPEC, "0.9.12"),
+    ECDSA_SHA384_P384(2, 96, 48, 48, 96, SigAlgo.EC, "SHA-384", "SHA384withECDSA", ECConstants.P384_SPEC, "1.2.840.10045.4.3.3", "0.9.12"),
     /**  Pubkey 132 bytes; privkey 66 bytes; hash 64 bytes; sig 132 bytes */
-    ECDSA_SHA512_P521(3, 132, 66, 64, 132, SigAlgo.EC, "SHA-512", "SHA512withECDSA", ECConstants.P521_SPEC, "0.9.12"),
+    ECDSA_SHA512_P521(3, 132, 66, 64, 132, SigAlgo.EC, "SHA-512", "SHA512withECDSA", ECConstants.P521_SPEC, "1.2.840.10045.4.3.4", "0.9.12"),
 
     /**  Pubkey 256 bytes; privkey 512 bytes; hash 32 bytes; sig 256 bytes */
-    RSA_SHA256_2048(4, 256, 512, 32, 256, SigAlgo.RSA, "SHA-256", "SHA256withRSA", RSAConstants.F4_2048_SPEC, "0.9.12"),
+    RSA_SHA256_2048(4, 256, 512, 32, 256, SigAlgo.RSA, "SHA-256", "SHA256withRSA", RSAConstants.F4_2048_SPEC, "1.2.840.113549.1.1.11", "0.9.12"),
     /**  Pubkey 384 bytes; privkey 768 bytes; hash 48 bytes; sig 384 bytes */
-    RSA_SHA384_3072(5, 384, 768, 48, 384, SigAlgo.RSA, "SHA-384", "SHA384withRSA", RSAConstants.F4_3072_SPEC, "0.9.12"),
+    RSA_SHA384_3072(5, 384, 768, 48, 384, SigAlgo.RSA, "SHA-384", "SHA384withRSA", RSAConstants.F4_3072_SPEC, "1.2.840.113549.1.1.12", "0.9.12"),
     /**  Pubkey 512 bytes; privkey 1024 bytes; hash 64 bytes; sig 512 bytes */
-    RSA_SHA512_4096(6, 512, 1024, 64, 512, SigAlgo.RSA, "SHA-512", "SHA512withRSA", RSAConstants.F4_4096_SPEC, "0.9.12"),
+    RSA_SHA512_4096(6, 512, 1024, 64, 512, SigAlgo.RSA, "SHA-512", "SHA512withRSA", RSAConstants.F4_4096_SPEC, "1.2.840.113549.1.1.13", "0.9.12"),
 
     /**
      *  Pubkey 32 bytes; privkey 32 bytes; hash 64 bytes; sig 64 bytes
@@ -55,7 +55,8 @@ public enum SigType {
      *  @since 0.9.15
      */
     EdDSA_SHA512_Ed25519(7, 32, 32, 64, 64, SigAlgo.EdDSA, "SHA-512", "SHA512withEdDSA",
-                         EdDSANamedCurveTable.getByName("ed25519-sha-512"), "0.9.17");
+                                                                            // this is the OID of the key, not the sig, probably wrong
+                         EdDSANamedCurveTable.getByName("ed25519-sha-512"), "1.3.101.100", "0.9.17");
 
 
     // TESTING....................
@@ -99,12 +100,12 @@ public enum SigType {
 
     private final int code, pubkeyLen, privkeyLen, hashLen, sigLen;
     private final SigAlgo base;
-    private final String digestName, algoName, since;
+    private final String digestName, algoName, oid, since;
     private final AlgorithmParameterSpec params;
     private final boolean isAvail;
 
     SigType(int cod, int pubLen, int privLen, int hLen, int sLen, SigAlgo baseAlgo,
-            String mdName, String aName, AlgorithmParameterSpec pSpec, String supportedSince) {
+            String mdName, String aName, AlgorithmParameterSpec pSpec, String oid, String supportedSince) {
         code = cod;
         pubkeyLen = pubLen;
         privkeyLen = privLen;
@@ -114,6 +115,7 @@ public enum SigType {
         digestName = mdName;
         algoName = aName;
         params = pSpec;
+        this.oid = oid;
         since = supportedSince;
         isAvail = x_isAvailable();
     }
@@ -183,6 +185,15 @@ public enum SigType {
         return since;
     }
 
+    /**
+     *  The OID for the signature.
+     *
+     *  @since 0.9.25
+     */
+    public String getOID() {
+        return oid;
+    }
+
     /**
      *  @since 0.9.12
      *  @return true if supported in this JVM
-- 
GitLab