Red Hat Application Migration Toolkit
package iaik.pkcs.pkcs10; import iaik.asn1.ASN; import iaik.asn1.ASN1; import iaik.asn1.ASN1Object; import iaik.asn1.BIT_STRING; import iaik.asn1.CON_SPEC; import iaik.asn1.CodingException; import iaik.asn1.DerCoder; import iaik.asn1.INTEGER; import iaik.asn1.ObjectID; import iaik.asn1.SEQUENCE; import iaik.asn1.SET; import iaik.asn1.structures.AlgorithmID; import iaik.asn1.structures.Attribute; import iaik.asn1.structures.AttributeValue; import iaik.asn1.structures.Name; import iaik.pkcs.PKCSException; import iaik.pkcs.PKCSParsingException; import iaik.pkcs.pkcs10.CertRequest; import iaik.utils.Util; import iaik.x509.PublicKeyInfo; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.Serializable; import java.math.BigInteger; import java.security.InvalidKeyException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.PublicKey; import java.security.Signature; import java.security.SignatureException; import java.util.Vector; public class CertificateRequest implements CertRequest, Serializable { // $FF: synthetic field static Class g; private byte[] j; private boolean k; private Attribute[] i; private byte[] f; private AlgorithmID c; private PublicKey e; private Name b; private int a; private ASN1 h; static Class a(String var0) { try { return Class.forName(var0); } catch (ClassNotFoundException var2) { throw new NoClassDefFoundError(var2.getMessage()); } } public void writeTo(OutputStream var1) throws IOException { this.c(); this.h.writeTo(var1); } private void writeObject(ObjectOutputStream var1) throws IOException { var1.write(this.toByteArray()); } public boolean verify(String var1) throws SignatureException { this.c(); try { Signature var2 = this.c.getSignatureInstance(var1); byte[] var3 = this.h.getFirstObject(); var2.initVerify(this.e); var2.update(var3); return var2.verify(this.f); } catch (CodingException var4) { throw new SignatureException(var4.getMessage()); } catch (NoSuchAlgorithmException var5) { throw new SignatureException(var5.getMessage()); } catch (InvalidKeyException var6) { throw new SignatureException(var6.getMessage()); } } public boolean verify() throws SignatureException { return this.verify((String)null); } public String toString(boolean var1) { StringBuffer var2 = new StringBuffer(); var2.append("Version: " + this.a + "\n"); if(this.b != null) { var2.append("Subject: " + this.b + "\n"); } if(this.e != null) { var2.append(this.e.toString()); } if(this.c != null) { var2.append("Signature algorithm: " + this.c + "\n"); } var2.append("\n"); if(this.i != null && this.i.length > 0) { if(var1) { for(int var3 = 0; var3 < this.i.length; ++var3) { var2.append("Attribute " + (var3 + 1) + ": "); var2.append(this.i[var3]); var2.append("\n"); } } else { var2.append("Attributes: yes\n"); } } var2.append("Fingerprint (MD5) : " + Util.toString(this.getFingerprint()) + "\n"); var2.append("Fingerprint (SHA-1): " + Util.toString(this.getFingerprintSHA()) + "\n"); return var2.toString(); } public String toString() { return this.toString(false); } public byte[] toByteArray() { this.c(); return this.h.toByteArray(); } public void sign(AlgorithmID var1, PrivateKey var2, String var3) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException { if(var2 == null) { throw new SignatureException("Cannot sign this request. No algorithm specified!"); } else if(var1 == null) { throw new InvalidKeyException("Cannot sign this request. No private key specified!"); } else { this.c = var1; Signature var4 = this.c.getSignatureInstance(var3); try { ASN1Object var5 = this.a(); var4.initSign(var2); var4.update(DerCoder.encode(var5)); this.f = var4.sign(); BIT_STRING var6 = new BIT_STRING(this.f); SEQUENCE var7 = null; var7 = new SEQUENCE(); var7.addComponent(var5); var7.addComponent(this.c.toASN1Object()); var7.addComponent(var6); this.h = new ASN1(var7); this.d(); this.e(); } catch (CodingException var8) { throw new SignatureException("Cann\'t sign CertRequest!"); } } } public void sign(AlgorithmID var1, PrivateKey var2) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException { this.sign(var1, var2, (String)null); } private void e() { this.k = false; } public void setSignature(AlgorithmID var1, byte[] var2) throws SignatureException { if(var1 == null) { throw new SignatureException("Cannot sign this request. No signature algorithm specified!"); } else if(var2 == null) { throw new SignatureException("Cannot sign this request. No signature value specified!"); } else { this.c = var1; this.f = var2; try { ASN1Object var3 = this.a(); BIT_STRING var4 = new BIT_STRING(this.f); SEQUENCE var5 = null; var5 = new SEQUENCE(); var5.addComponent(var3); var5.addComponent(this.c.toASN1Object()); var5.addComponent(var4); this.h = new ASN1(var5); this.d(); this.e(); } catch (CodingException var6) { throw new SignatureException("Cann\'t sign CertRequest!"); } } } private void d() { this.k = true; this.j = null; } public void setAttributes(Attribute[] var1) { this.i = var1; this.d(); } private void readObject(ObjectInputStream var1) throws ClassNotFoundException, IOException { try { this.h = new ASN1(var1); this.b(); } catch (CodingException var3) { throw new IOException("Unable to restore CertificateRequest: " + var3.toString()); } catch (PKCSParsingException var4) { throw new IOException("Unable to restore CertificateRequest: " + var4.toString()); } } public int getVersion() { return this.a; } public Name getSubject() { return this.b; } public AlgorithmID getSignatureAlgorithmID() { return this.c; } public PublicKey getPublicKey() { return this.e; } public byte[] getFingerprintSHA() { if(this.j == null) { try { this.j = this.getFingerprint("SHA"); } catch (NoSuchAlgorithmException var2) { throw new RuntimeException("Algorithm SHA not available: " + var2.toString()); } } return this.j; } public byte[] getFingerprint(String var1) throws NoSuchAlgorithmException { this.c(); MessageDigest var2 = MessageDigest.getInstance(var1); var2.update(this.h.toByteArray()); return var2.digest(); } public byte[] getFingerprint() { this.c(); return this.h.fingerprint(); } public byte[] getCertificateRequestInfo() throws PKCSException { try { return this.h != null && this.h.toByteArray() != null?this.h.getFirstObject():DerCoder.encode(this.a()); } catch (CodingException var2) { throw new PKCSException(var2.toString()); } } public Attribute[] getAttributes(ObjectID var1) { if(this.i == null) { return null; } else { Vector var2 = new Vector(); for(int var3 = 0; var3 < this.i.length; ++var3) { Attribute var4 = this.i[var3]; if(var4.getType().equals(var1)) { var2.addElement(this.i[var3]); } } if(var2.isEmpty()) { return null; } else { Attribute[] var5 = new Attribute[var2.size()]; var2.copyInto(var5); return var5; } } } public Attribute[] getAttributes() { return this.i; } public AttributeValue getAttributeValue(ObjectID var1) throws PKCSException { Attribute var2 = this.getAttribute(var1); if(var2 != null) { try { return var2.getAttributeValue(); } catch (CodingException var4) { throw new PKCSException("Cannot decode attribute " + var1.getName() + ": " + var4.getMessage()); } } else { return null; } } public Attribute getAttribute(ObjectID var1) { if(this.i == null) { return null; } else { for(int var2 = 0; var2 < this.i.length; ++var2) { if(this.i[var2].getType().equals(var1)) { return this.i[var2]; } } return null; } } private void b() throws PKCSParsingException { try { ASN1Object var1 = this.h.getComponentAt(0); this.c = new AlgorithmID(this.h.getComponentAt(1)); ASN1Object var2 = this.h.getComponentAt(2); this.f = (byte[])((BIT_STRING)var2).getValue(); this.a = ((BigInteger)var1.getComponentAt(0).getValue()).intValue(); this.b = new Name(var1.getComponentAt(1)); try { this.e = PublicKeyInfo.getPublicKey(var1.getComponentAt(2)); } catch (InvalidKeyException var4) { throw new PKCSParsingException("Unable to create PublicKey: " + var4.toString()); } if(var1.countComponents() > 3) { ASN1Object var3 = var1.getComponentAt(3); ((CON_SPEC)var3).forceImplicitlyTagged(ASN.SEQUENCE); if(var3.getAsnType().getTag() != 0) { throw new PKCSParsingException("Unknown context specific tag: " + var3.getAsnType().getTag()); } this.i = (Attribute[])ASN.parseSequenceOf((ASN1Object)var3.getValue(), g != null?g:(g = a("iaik.asn1.structures.Attribute"))); } this.h.clearASN1Object(); this.e(); } catch (RuntimeException var5) { throw new PKCSParsingException("Certificate request format error: " + var5.toString()); } catch (CodingException var6) { throw new PKCSParsingException(var6.toString()); } } private ASN1Object a() throws CodingException { SEQUENCE var1 = new SEQUENCE(); var1.addComponent(new INTEGER(this.a)); var1.addComponent(this.b.toASN1Object()); var1.addComponent(DerCoder.decode(this.e.getEncoded())); if(this.i != null) { var1.addComponent(new CON_SPEC(0, ASN.createSetOf(this.i), true)); } else { var1.addComponent(new CON_SPEC(0, new SET(), true)); } return var1; } private void c() { if(this.k) { throw new RuntimeException("Cannot perform operation, certificate has to be signed first"); } } public void addAttribute(Attribute var1) { if(this.i == null) { this.i = new Attribute[]{var1}; } else { Attribute[] var2 = new Attribute[this.i.length + 1]; System.arraycopy(this.i, 0, var2, 0, this.i.length); var2[this.i.length] = var1; this.i = var2; this.d(); } } public CertificateRequest(byte[] var1) throws PKCSParsingException { try { this.h = new ASN1(var1); this.b(); } catch (CodingException var3) { throw new PKCSParsingException(var3.toString()); } } public CertificateRequest(PublicKey var1, Name var2) throws InvalidKeyException { this.e = var1; this.b = var2; this.d(); this.a = 0; } public CertificateRequest(InputStream var1) throws PKCSParsingException, IOException { try { this.h = new ASN1(var1); this.b(); } catch (CodingException var3) { throw new PKCSParsingException(var3.toString()); } } static { Util.toString((byte[])null, -1, 1); } }