X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Fpages%2Faccount%2FCertificateIssueForm.java;h=4332a39142f630acf7986e7292b2186cda98b05a;hb=6443cd493db6d0241968e15c59a067684e42d0a8;hp=6e7592539f85a09ed34ac64454f21e29c075ef24;hpb=7e0cef98baeba1306d914348988ae842b89102f4;p=gigi.git
diff --git a/src/org/cacert/gigi/pages/account/CertificateIssueForm.java b/src/org/cacert/gigi/pages/account/CertificateIssueForm.java
index 6e759253..4332a391 100644
--- a/src/org/cacert/gigi/pages/account/CertificateIssueForm.java
+++ b/src/org/cacert/gigi/pages/account/CertificateIssueForm.java
@@ -42,6 +42,7 @@ import sun.security.pkcs10.PKCS10Attribute;
import sun.security.pkcs10.PKCS10Attributes;
import sun.security.util.DerInputStream;
import sun.security.util.DerValue;
+import sun.security.util.ObjectIdentifier;
import sun.security.x509.AVA;
import sun.security.x509.AlgorithmId;
import sun.security.x509.CertificateExtensions;
@@ -51,6 +52,7 @@ import sun.security.x509.Extension;
import sun.security.x509.GeneralName;
import sun.security.x509.GeneralNameInterface;
import sun.security.x509.GeneralNames;
+import sun.security.x509.PKIXExtensions;
import sun.security.x509.RDN;
import sun.security.x509.RFC822Name;
import sun.security.x509.SubjectAlternativeNameExtension;
@@ -68,6 +70,30 @@ public class CertificateIssueForm extends Form {
private final static Template tIni = new Template(CertificateAdd.class.getResource("RequestCertificate.templ"));
+ public static final ObjectIdentifier OID_KEY_USAGE_SSL_SERVER = ObjectIdentifier.newInternal(new int[] {
+ 1, 3, 6, 1, 5, 5, 7, 3, 1
+ });
+
+ public static final ObjectIdentifier OID_KEY_USAGE_SSL_CLIENT = ObjectIdentifier.newInternal(new int[] {
+ 1, 3, 6, 1, 5, 5, 7, 3, 2
+ });
+
+ public static final ObjectIdentifier OID_KEY_USAGE_CODESIGN = ObjectIdentifier.newInternal(new int[] {
+ 1, 3, 6, 1, 5, 5, 7, 3, 3
+ });
+
+ public static final ObjectIdentifier OID_KEY_USAGE_EMAIL_PROTECTION = ObjectIdentifier.newInternal(new int[] {
+ 1, 3, 6, 1, 5, 5, 7, 3, 4
+ });
+
+ public static final ObjectIdentifier OID_KEY_USAGE_TIMESTAMP = ObjectIdentifier.newInternal(new int[] {
+ 1, 3, 6, 1, 5, 5, 7, 3, 8
+ });
+
+ public static final ObjectIdentifier OID_KEY_USAGE_OCSP = ObjectIdentifier.newInternal(new int[] {
+ 1, 3, 6, 1, 5, 5, 7, 3, 9
+ });
+
User u;
private CSRType csrType;
@@ -84,6 +110,8 @@ public class CertificateIssueForm extends Form {
boolean login;
+ CertificateProfile profile = CertificateProfile.getById(1);
+
public CertificateIssueForm(HttpServletRequest hsr) {
super(hsr);
u = Page.getUser(hsr);
@@ -119,7 +147,14 @@ public class CertificateIssueForm extends Form {
if (a.getObjectIdentifier().equals((Object) PKCS9Attribute.EMAIL_ADDRESS_OID)) {
SANs.add(new SubjectAlternateName(SANType.EMAIL, a.getValueString()));
} else if (a.getObjectIdentifier().equals((Object) X500Name.commonName_oid)) {
- CN = a.getValueString();
+ String value = a.getValueString();
+ if (value.contains(".") && !value.contains(" ")) {
+ SANs.add(new SubjectAlternateName(SANType.DNS, value));
+ } else {
+ CN = value;
+ }
+ } else if (a.getObjectIdentifier().equals((Object) PKIXExtensions.SubjectAlternativeName_Id)) {
+ // parse invalid SANs
}
}
}
@@ -141,17 +176,20 @@ public class CertificateIssueForm extends Form {
} else if (c instanceof ExtendedKeyUsageExtension) {
ExtendedKeyUsageExtension ekue = (ExtendedKeyUsageExtension) c;
for (String s : ekue.getExtendedKeyUsage()) {
- if (s.equals("1.3.6.1.5.5.7.3.1")) {
+ if (s.equals(OID_KEY_USAGE_SSL_SERVER.toString())) {
// server
- } else if (s.equals("1.3.6.1.5.5.7.3.2")) {
+ profile = CertificateProfile.getByName("server");
+ } else if (s.equals(OID_KEY_USAGE_SSL_CLIENT.toString())) {
// client
- } else if (s.equals("1.3.6.1.5.5.7.3.3")) {
+ profile = CertificateProfile.getByName("client");
+ } else if (s.equals(OID_KEY_USAGE_CODESIGN.toString())) {
// code sign
- } else if (s.equals("1.3.6.1.5.5.7.3.4")) {
+ } else if (s.equals(OID_KEY_USAGE_EMAIL_PROTECTION.toString())) {
// emailProtection
- } else if (s.equals("1.3.6.1.5.5.7.3.8")) {
+ profile = CertificateProfile.getByName("mail");
+ } else if (s.equals(OID_KEY_USAGE_TIMESTAMP.toString())) {
// timestamp
- } else if (s.equals("1.3.6.1.5.5.7.3.9")) {
+ } else if (s.equals(OID_KEY_USAGE_OCSP.toString())) {
// OCSP
}
}
@@ -168,6 +206,8 @@ public class CertificateIssueForm extends Form {
PublicKey pk = parsed.getSubjectPublicKeyInfo();
checkKeyStrength(pk, out);
String sign = getSignatureAlgorithm(data);
+ guessDigest(sign);
+
out.println("
digest: " + sign + "
");
this.csr = csr;
@@ -181,6 +221,7 @@ public class CertificateIssueForm extends Form {
}
checkKeyStrength(parsed.getPubkey(), out);
String sign = getSignatureAlgorithm(data);
+ guessDigest(sign);
out.println("
digest: " + sign + "
");
// spkacChallenge
@@ -194,14 +235,12 @@ public class CertificateIssueForm extends Form {
if (hashAlg != null) {
selectedDigest = Digest.valueOf(hashAlg);
}
- CertificateProfile profile = CertificateProfile.getByName(req.getParameter("profile"));
+ profile = CertificateProfile.getByName(req.getParameter("profile"));
String pDNS = null;
String pMail = null;
Set filteredSANs = new LinkedHashSet<>();
boolean server = profile.getKeyName().equals("server");
- boolean dirty = false;
- ;
for (SubjectAlternateName san : parseSANBox(req.getParameter("SANs"))) {
if (san.getType() == SANType.DNS) {
if (u.isValidDomain(san.getName()) && server) {
@@ -220,7 +259,6 @@ public class CertificateIssueForm extends Form {
continue;
}
}
- dirty = true;
outputError(out, req, "The requested Subject alternate name \"%s\" has been removed.",//
san.getType().toString().toLowerCase() + ":" + san.getName());
}
@@ -280,14 +318,33 @@ public class CertificateIssueForm extends Form {
return false;
}
+ private void guessDigest(String sign) {
+ if (sign.toLowerCase().startsWith("sha512")) {
+ selectedDigest = Digest.SHA512;
+ } else if (sign.toLowerCase().startsWith("sha384")) {
+ selectedDigest = Digest.SHA384;
+ }
+ }
+
private TreeSet parseSANBox(String SANs) {
String[] SANparts = SANs.split("[\r\n]+|, *");
TreeSet parsedNames = new TreeSet<>();
for (String SANline : SANparts) {
String[] parts = SANline.split(":", 2);
+ if (parts.length == 1) {
+ if (parts[0].trim().equals("")) {
+ continue;
+ }
+ if (parts[0].contains("@")) {
+ parsedNames.add(new SubjectAlternateName(SANType.EMAIL, parts[0]));
+ } else {
+ parsedNames.add(new SubjectAlternateName(SANType.DNS, parts[0]));
+ }
+ continue;
+ }
try {
SANType t = Certificate.SANType.valueOf(parts[0].toUpperCase());
- if (t == null || parts.length == 1) {
+ if (t == null) {
continue;
}
parsedNames.add(new SubjectAlternateName(t, parts[1]));
@@ -362,6 +419,11 @@ public class CertificateIssueForm extends Form {
if (cp == null) {
return false;
}
+ if (cp.getId() == profile.getId()) {
+ vars.put("selected", " selected");
+ } else {
+ vars.put("selected", "");
+ }
vars.put("key", cp.getKeyName());
vars.put("name", cp.getVisibleName());
return true;