Search in sources :

Example 1 with RSAParameters

use of org.xipki.ca.certprofile.x509.jaxb.RSAParameters in project xipki by xipki.

the class ProfileConfCreatorDemo method createKeyAlgorithms.

// method getBaseProfile
private static KeyAlgorithms createKeyAlgorithms(ASN1ObjectIdentifier[] curveIds) {
    KeyAlgorithms ret = new KeyAlgorithms();
    List<AlgorithmType> list = ret.getAlgorithm();
    // RSA
    AlgorithmType algorithm = new AlgorithmType();
    list.add(algorithm);
    algorithm.getAlgorithm().add(createOidType(PKCSObjectIdentifiers.rsaEncryption, "RSA"));
    RSAParameters rsaParams = new RSAParameters();
    algorithm.setParameters(createKeyParametersType(rsaParams));
    RangesType ranges = new RangesType();
    rsaParams.setModulusLength(ranges);
    List<RangeType> modulusLengths = ranges.getRange();
    modulusLengths.add(createRange(1024));
    modulusLengths.add(createRange(2048));
    modulusLengths.add(createRange(3072));
    modulusLengths.add(createRange(4096));
    // DSA
    algorithm = new AlgorithmType();
    list.add(algorithm);
    algorithm.getAlgorithm().add(createOidType(X9ObjectIdentifiers.id_dsa, "DSA"));
    DSAParameters dsaParams = new DSAParameters();
    algorithm.setParameters(createKeyParametersType(dsaParams));
    ranges = new RangesType();
    dsaParams.setPLength(ranges);
    List<RangeType> plengths = ranges.getRange();
    plengths.add(createRange(1024));
    plengths.add(createRange(2048));
    plengths.add(createRange(3072));
    ranges = new RangesType();
    dsaParams.setQLength(ranges);
    List<RangeType> qlengths = ranges.getRange();
    qlengths.add(createRange(160));
    qlengths.add(createRange(224));
    qlengths.add(createRange(256));
    // EC
    algorithm = new AlgorithmType();
    list.add(algorithm);
    algorithm.getAlgorithm().add(createOidType(X9ObjectIdentifiers.id_ecPublicKey, "EC"));
    ECParameters ecParams = new ECParameters();
    algorithm.setParameters(createKeyParametersType(ecParams));
    if (curveIds != null && curveIds.length > 0) {
        Curves curves = new Curves();
        ecParams.setCurves(curves);
        for (ASN1ObjectIdentifier curveId : curveIds) {
            String name = AlgorithmUtil.getCurveName(curveId);
            curves.getCurve().add(createOidType(curveId, name));
        }
    }
    ecParams.setPointEncodings(new PointEncodings());
    final Byte unpressed = 4;
    ecParams.getPointEncodings().getPointEncoding().add(unpressed);
    return ret;
}
Also used : RSAParameters(org.xipki.ca.certprofile.x509.jaxb.RSAParameters) KeyAlgorithms(org.xipki.ca.certprofile.x509.jaxb.X509ProfileType.KeyAlgorithms) ECParameters(org.xipki.ca.certprofile.x509.jaxb.ECParameters) PointEncodings(org.xipki.ca.certprofile.x509.jaxb.ECParameters.PointEncodings) RangeType(org.xipki.ca.certprofile.x509.jaxb.RangeType) AlgorithmType(org.xipki.ca.certprofile.x509.jaxb.AlgorithmType) RangesType(org.xipki.ca.certprofile.x509.jaxb.RangesType) DSAParameters(org.xipki.ca.certprofile.x509.jaxb.DSAParameters) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) Curves(org.xipki.ca.certprofile.x509.jaxb.ECParameters.Curves)

Example 2 with RSAParameters

use of org.xipki.ca.certprofile.x509.jaxb.RSAParameters in project xipki by xipki.

the class ProfileConfCreatorDemo method createRSAKeyAlgorithms.

// method createKeyAlgorithms
// CHECKSTYLE:SKIP
private static KeyAlgorithms createRSAKeyAlgorithms() {
    KeyAlgorithms ret = new KeyAlgorithms();
    List<AlgorithmType> list = ret.getAlgorithm();
    AlgorithmType algorithm = new AlgorithmType();
    list.add(algorithm);
    algorithm.getAlgorithm().add(createOidType(PKCSObjectIdentifiers.rsaEncryption, "RSA"));
    RSAParameters params = new RSAParameters();
    algorithm.setParameters(createKeyParametersType(params));
    RangesType ranges = new RangesType();
    params.setModulusLength(ranges);
    List<RangeType> modulusLengths = ranges.getRange();
    modulusLengths.add(createRange(2048));
    modulusLengths.add(createRange(3072));
    modulusLengths.add(createRange(4096));
    return ret;
}
Also used : RSAParameters(org.xipki.ca.certprofile.x509.jaxb.RSAParameters) RangeType(org.xipki.ca.certprofile.x509.jaxb.RangeType) AlgorithmType(org.xipki.ca.certprofile.x509.jaxb.AlgorithmType) KeyAlgorithms(org.xipki.ca.certprofile.x509.jaxb.X509ProfileType.KeyAlgorithms) RangesType(org.xipki.ca.certprofile.x509.jaxb.RangesType)

Example 3 with RSAParameters

use of org.xipki.ca.certprofile.x509.jaxb.RSAParameters in project xipki by xipki.

the class XmlX509CertprofileUtil method convertKeyParametersOption.

private static KeyParametersOption convertKeyParametersOption(AlgorithmType type) throws CertprofileException {
    ParamUtil.requireNonNull("type", type);
    if (type.getParameters() == null || type.getParameters().getAny() == null) {
        return KeyParametersOption.ALLOW_ALL;
    }
    Object paramsObj = type.getParameters().getAny();
    if (paramsObj instanceof ECParameters) {
        ECParameters params = (ECParameters) paramsObj;
        KeyParametersOption.ECParamatersOption option = new KeyParametersOption.ECParamatersOption();
        if (params.getCurves() != null) {
            Curves curves = params.getCurves();
            Set<ASN1ObjectIdentifier> curveOids = toOidSet(curves.getCurve());
            option.setCurveOids(curveOids);
        }
        if (params.getPointEncodings() != null) {
            List<Byte> bytes = params.getPointEncodings().getPointEncoding();
            Set<Byte> pointEncodings = new HashSet<>(bytes);
            option.setPointEncodings(pointEncodings);
        }
        return option;
    } else if (paramsObj instanceof RSAParameters) {
        RSAParameters params = (RSAParameters) paramsObj;
        KeyParametersOption.RSAParametersOption option = new KeyParametersOption.RSAParametersOption();
        Set<Range> modulusLengths = buildParametersMap(params.getModulusLength());
        option.setModulusLengths(modulusLengths);
        return option;
    } else if (paramsObj instanceof RSAPSSParameters) {
        RSAPSSParameters params = (RSAPSSParameters) paramsObj;
        KeyParametersOption.RSAPSSParametersOption option = new KeyParametersOption.RSAPSSParametersOption();
        Set<Range> modulusLengths = buildParametersMap(params.getModulusLength());
        option.setModulusLengths(modulusLengths);
        return option;
    } else if (paramsObj instanceof DSAParameters) {
        DSAParameters params = (DSAParameters) paramsObj;
        KeyParametersOption.DSAParametersOption option = new KeyParametersOption.DSAParametersOption();
        Set<Range> plengths = buildParametersMap(params.getPLength());
        option.setPlengths(plengths);
        Set<Range> qlengths = buildParametersMap(params.getQLength());
        option.setQlengths(qlengths);
        return option;
    } else if (paramsObj instanceof DHParameters) {
        DHParameters params = (DHParameters) paramsObj;
        KeyParametersOption.DHParametersOption option = new KeyParametersOption.DHParametersOption();
        Set<Range> plengths = buildParametersMap(params.getPLength());
        option.setPlengths(plengths);
        Set<Range> qlengths = buildParametersMap(params.getQLength());
        option.setQlengths(qlengths);
        return option;
    } else if (paramsObj instanceof GostParameters) {
        GostParameters params = (GostParameters) paramsObj;
        KeyParametersOption.GostParametersOption option = new KeyParametersOption.GostParametersOption();
        Set<ASN1ObjectIdentifier> set = toOidSet(params.getPublicKeyParamSet());
        option.setPublicKeyParamSets(set);
        set = toOidSet(params.getDigestParamSet());
        option.setDigestParamSets(set);
        set = toOidSet(params.getEncryptionParamSet());
        option.setEncryptionParamSets(set);
        return option;
    } else {
        throw new CertprofileException("unknown public key parameters type " + paramsObj.getClass().getName());
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ECParameters(org.xipki.ca.certprofile.x509.jaxb.ECParameters) CertprofileException(org.xipki.ca.api.profile.CertprofileException) GostParameters(org.xipki.ca.certprofile.x509.jaxb.GostParameters) RSAPSSParameters(org.xipki.ca.certprofile.x509.jaxb.RSAPSSParameters) HashSet(java.util.HashSet) RSAParameters(org.xipki.ca.certprofile.x509.jaxb.RSAParameters) DHParameters(org.xipki.ca.certprofile.x509.jaxb.DHParameters) Range(org.xipki.ca.api.profile.Range) KeyParametersOption(org.xipki.ca.api.profile.KeyParametersOption) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) DSAParameters(org.xipki.ca.certprofile.x509.jaxb.DSAParameters) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) Curves(org.xipki.ca.certprofile.x509.jaxb.ECParameters.Curves)

Aggregations

RSAParameters (org.xipki.ca.certprofile.x509.jaxb.RSAParameters)3 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)2 AlgorithmType (org.xipki.ca.certprofile.x509.jaxb.AlgorithmType)2 DSAParameters (org.xipki.ca.certprofile.x509.jaxb.DSAParameters)2 ECParameters (org.xipki.ca.certprofile.x509.jaxb.ECParameters)2 Curves (org.xipki.ca.certprofile.x509.jaxb.ECParameters.Curves)2 RangeType (org.xipki.ca.certprofile.x509.jaxb.RangeType)2 RangesType (org.xipki.ca.certprofile.x509.jaxb.RangesType)2 KeyAlgorithms (org.xipki.ca.certprofile.x509.jaxb.X509ProfileType.KeyAlgorithms)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 DERTaggedObject (org.bouncycastle.asn1.DERTaggedObject)1 CertprofileException (org.xipki.ca.api.profile.CertprofileException)1 KeyParametersOption (org.xipki.ca.api.profile.KeyParametersOption)1 Range (org.xipki.ca.api.profile.Range)1 DHParameters (org.xipki.ca.certprofile.x509.jaxb.DHParameters)1 PointEncodings (org.xipki.ca.certprofile.x509.jaxb.ECParameters.PointEncodings)1 GostParameters (org.xipki.ca.certprofile.x509.jaxb.GostParameters)1 RSAPSSParameters (org.xipki.ca.certprofile.x509.jaxb.RSAPSSParameters)1