Package org.w3._2002._03.xkms_

Examples of org.w3._2002._03.xkms_.RequestAbstractType


                byte[] second = XKMSUtil.getSecretKeyFromPassphrase(new String(first,"ISO8859-1"), false,20, XKMSUtil.KEY_REVOCATIONCODEIDENTIFIER_PASS2).getEncoded();
                prototypeKeyBinding.setRevocationCodeIdentifier(second);
            }
           
            String reqId = genId();
            RegisterRequestType registerRequestType = xKMSObjectFactory.createRegisterRequestType();
            registerRequestType.setId(reqId);
            registerRequestType.getRespondWith().add(XKMSConstants.RESPONDWITH_X509CHAIN);
            if(keySize == 0){
              registerRequestType.getRespondWith().add(XKMSConstants.RESPONDWITH_PRIVATEKEY);
            }
            registerRequestType.setPrototypeKeyBinding(prototypeKeyBinding);
           
            RegisterResultType registerResultType = null;
            if(genKeys == null){
              registerResultType = getXKMSInvoker().register(registerRequestType, clientCert, privateKey, password, null, keyBindingId);
            }else{
View Full Code Here


 
  public void test04TestPublicKeyExtraction() throws Exception{
        DocumentBuilder db = dbf.newDocumentBuilder();
        KeyPair keys = KeyTools.genKeys("1024", "RSA");   
       
      RegisterRequestType registerRequestType = xKMSObjectFactory.createRegisterRequestType();
      registerRequestType.setId("523");        
         
        UseKeyWithType useKeyWithType = xKMSObjectFactory.createUseKeyWithType();
        useKeyWithType.setApplication(XKMSConstants.USEKEYWITH_PKIX);
        useKeyWithType.setIdentifier("CN=Test Testarsson");
       
        registerRequestType.getRespondWith().add(XKMSConstants.RESPONDWITH_X509CHAIN);
     
        KeyInfoType keyInfoType = sigFactory.createKeyInfoType();
        RSAKeyValueType rsaKeyValueType = sigFactory.createRSAKeyValueType();
        rsaKeyValueType.setExponent(((RSAPublicKey) keys.getPublic()).getPublicExponent().toByteArray());
        rsaKeyValueType.setModulus(((RSAPublicKey) keys.getPublic()).getModulus().toByteArray());
        JAXBElement<RSAKeyValueType> rsaKeyValue = sigFactory.createRSAKeyValue(rsaKeyValueType);
        keyInfoType.getContent().add(rsaKeyValue);
        PrototypeKeyBindingType prototypeKeyBindingType = xKMSObjectFactory.createPrototypeKeyBindingType();
        prototypeKeyBindingType.getUseKeyWith().add(useKeyWithType);
        prototypeKeyBindingType.setKeyInfo(keyInfoType);
        prototypeKeyBindingType.setId("100231");
        registerRequestType.setPrototypeKeyBinding(prototypeKeyBindingType);               
        JAXBElement<RegisterRequestType> registerRequest = xKMSObjectFactory.createRegisterRequest(registerRequestType);

        Document registerRequestDoc = db.newDocument();
        marshaller.marshal( registerRequest, registerRequestDoc );

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        XMLUtils.outputDOM(registerRequestDoc, baos);
        log.debug("XMLUtils.outputDOM: " + baos.toString());
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());

        JAXBElement<RegisterRequestType> registerRequest2 = (JAXBElement<RegisterRequestType>) unmarshaller.unmarshal(bais);
        registerRequestType = registerRequest2.getValue();
       
        RSAKeyValueType rSAKeyValueType  = (RSAKeyValueType) ((JAXBElement) registerRequestType.getPrototypeKeyBinding().getKeyInfo().getContent().get(0)).getValue();       
        RSAPublicKeySpec rSAPublicKeySpec = new RSAPublicKeySpec(new BigInteger(rSAKeyValueType.getModulus()), new BigInteger(rSAKeyValueType.getExponent()));       
        RSAPublicKey rSAPublicKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(rSAPublicKeySpec);
       
        X509Certificate cert = CertTools.genSelfCert("CN=test", 10, null,keys.getPrivate(), rSAPublicKey, "SHA1WithRSA", true);
       
View Full Code Here

        String alias = "TEST";
        java.security.cert.X509Certificate pkCert = (java.security.cert.X509Certificate) clientKeyStore.getCertificate(alias);

        Key key = clientKeyStore.getKey(alias, "foo123".toCharArray());

        RegisterRequestType registerRequestType = xKMSObjectFactory.createRegisterRequestType();
        registerRequestType.setId("500");

        UseKeyWithType useKeyWithType = xKMSObjectFactory.createUseKeyWithType();
        useKeyWithType.setApplication(XKMSConstants.USEKEYWITH_PKIX);
        useKeyWithType.setIdentifier("CN=Test Testarsson");

        registerRequestType.getRespondWith().add(XKMSConstants.RESPONDWITH_X509CHAIN);

        KeyInfoType keyInfoType = sigFactory.createKeyInfoType();
        RSAKeyValueType rsaKeyValueType = sigFactory.createRSAKeyValueType();
        rsaKeyValueType.setExponent(((RSAPublicKey) pkCert.getPublicKey()).getPublicExponent().toByteArray());
        rsaKeyValueType.setModulus(((RSAPublicKey) pkCert.getPublicKey()).getModulus().toByteArray());
        JAXBElement<RSAKeyValueType> rsaKeyValue = sigFactory.createRSAKeyValue(rsaKeyValueType);
        keyInfoType.getContent().add(rsaKeyValue);
        PrototypeKeyBindingType prototypeKeyBindingType = xKMSObjectFactory.createPrototypeKeyBindingType();
        prototypeKeyBindingType.getUseKeyWith().add(useKeyWithType);
        prototypeKeyBindingType.setKeyInfo(keyInfoType);
        prototypeKeyBindingType.setId("100231");
        registerRequestType.setPrototypeKeyBinding(prototypeKeyBindingType);
        JAXBElement<RegisterRequestType> registerRequest = xKMSObjectFactory.createRegisterRequest(registerRequestType);

        Document registerRequestDoc = dbf.newDocumentBuilder().newDocument();
        marshaller.marshal(registerRequest, registerRequestDoc);
View Full Code Here

        KeyPair keyPair = KeyTools.genKeys("1024", "RSA");

        String alias = "TEST";
        java.security.cert.X509Certificate pkCert = (java.security.cert.X509Certificate) clientKeyStore.getCertificate(alias);

        RegisterRequestType registerRequestType = xKMSObjectFactory.createRegisterRequestType();
        registerRequestType.setId("500");

        UseKeyWithType useKeyWithType = xKMSObjectFactory.createUseKeyWithType();
        useKeyWithType.setApplication(XKMSConstants.USEKEYWITH_PKIX);
        useKeyWithType.setIdentifier("CN=Test Testarsson");

        registerRequestType.getRespondWith().add(XKMSConstants.RESPONDWITH_X509CHAIN);

        KeyInfoType keyInfoType = sigFactory.createKeyInfoType();
        RSAKeyValueType rsaKeyValueType = sigFactory.createRSAKeyValueType();
        rsaKeyValueType.setExponent(((RSAPublicKey) keyPair.getPublic()).getPublicExponent().toByteArray());
        rsaKeyValueType.setModulus(((RSAPublicKey) keyPair.getPublic()).getModulus().toByteArray());
        JAXBElement<RSAKeyValueType> rsaKeyValue = sigFactory.createRSAKeyValue(rsaKeyValueType);
        keyInfoType.getContent().add(rsaKeyValue);
        PrototypeKeyBindingType prototypeKeyBindingType = xKMSObjectFactory.createPrototypeKeyBindingType();
        prototypeKeyBindingType.getUseKeyWith().add(useKeyWithType);
        prototypeKeyBindingType.setKeyInfo(keyInfoType);
        prototypeKeyBindingType.setId("100231");
        registerRequestType.setPrototypeKeyBinding(prototypeKeyBindingType);
        JAXBElement<RegisterRequestType> registerRequest = xKMSObjectFactory.createRegisterRequest(registerRequestType);

        Document registerRequestDoc = dbf.newDocumentBuilder().newDocument();
        marshaller.marshal(registerRequest, registerRequestDoc);
View Full Code Here

   * Returns a register response
   */
  public RegisterResultType getResponse(boolean requestVerifies){
    RegisterResultType result = xkmsFactory.createRegisterResultType();   
    super.populateResponse(result, requestVerifies);   
    RegisterRequestType req = (RegisterRequestType) this.req;

    if(resultMajor == null){    
      if(!checkValidRespondWithRequest(req.getRespondWith(),false)){
        resultMajor = XKMSConstants.RESULTMAJOR_SENDER;
        resultMinor = XKMSConstants.RESULTMINOR_MESSAGENOTSUPPORTED;
      }
      if(resultMajor == null){
        if(resultMajor == null){   // TODO: Bug??
          PublicKey publicKey = getPublicKey(req);         
          if(confirmPOP(publicKey)){
            String subjectDN = getSubjectDN(req);
            UserDataVO userData = findUserData(subjectDN);
            if(userData != null){
              String password = ""
              boolean encryptedPassword = isPasswordEncrypted(req);
              if(encryptedPassword){
                password = getEncryptedPassword(requestDoc, userData.getPassword());
              }else{
                password = getClearPassword(req, userData.getPassword());
              }
              String revocationCode = getRevocationCode(req);
              if(password != null ){
                X509Certificate cert = registerReissueOrRecover(false,false, result, userData,password, publicKey, revocationCode);
                if(cert != null){
                  KeyBindingAbstractType keyBinding = getResponseValues(req.getPrototypeKeyBinding(), cert, false, true);
                  result.getKeyBinding().add((KeyBindingType) keyBinding);
                }
              }
            }
          }
View Full Code Here

            if(keySize == 0){
              registerRequestType.getRespondWith().add(XKMSConstants.RESPONDWITH_PRIVATEKEY);
            }
            registerRequestType.setPrototypeKeyBinding(prototypeKeyBinding);
           
            RegisterResultType registerResultType = null;
            if(genKeys == null){
              registerResultType = getXKMSInvoker().register(registerRequestType, clientCert, privateKey, password, null, keyBindingId);
            }else{
              KeyInfoType keyInfoType = sigFactory.createKeyInfoType();
                RSAKeyValueType rsaKeyValueType = sigFactory.createRSAKeyValueType();
                rsaKeyValueType.setExponent(((RSAPublicKey) genKeys.getPublic()).getPublicExponent().toByteArray());
                rsaKeyValueType.setModulus(((RSAPublicKey) genKeys.getPublic()).getModulus().toByteArray());
                JAXBElement<RSAKeyValueType> rsaKeyValue = sigFactory.createRSAKeyValue(rsaKeyValueType);
                keyInfoType.getContent().add(rsaKeyValue);
               
                prototypeKeyBinding.setKeyInfo(keyInfoType);
             
              registerResultType = getXKMSInvoker().register(registerRequestType, clientCert, privateKey, password, genKeys.getPrivate(), keyBindingId);             
            }
           
            if(registerResultType.getResultMajor().equals(XKMSConstants.RESULTMAJOR_SUCCESS) &&
               registerResultType.getResultMinor() == null){
           
                if(registerResultType.getKeyBinding().size() >0){
                  KeyBindingType keyBinding = registerResultType.getKeyBinding().get(0);                 
                  List certs = getCertsFromKeyBinding(keyBinding);
                   
                  X509Certificate userCert = getUserCert(certs);                 
                  certs.remove(userCert);
                 
                  if(registerResultType.getPrivateKey() != null){
                    PrivateKey serverKey = XKMSUtil.getPrivateKeyFromEncryptedXML(registerResultType.getPrivateKey(), password);
                    createKeyStore(userCert, certs, serverKey,password,encoding,outputPath);
                  }else{
                    createKeyStore(userCert, certs,genKeys.getPrivate(),password,encoding,outputPath);
                  }
View Full Code Here

    }
 
    public void test01KeyEncryption() throws Exception {
        DocumentBuilder db = dbf.newDocumentBuilder();
        KeyPair keys = KeyTools.genKeys("1024", "RSA");                               
        RegisterResultType registerResultType = xKMSObjectFactory.createRegisterResultType();
        JAXBElement<RegisterResultType> registerResult = xKMSObjectFactory.createRegisterResult(registerResultType);
               
        PrivateKeyType privateKeyType1 = XKMSUtil.getEncryptedXMLFromPrivateKey( (RSAPrivateCrtKey) keys.getPrivate(), "This is total crap");
        registerResultType.setPrivateKey(privateKeyType1);
       
        Document registerResultDoc = db.newDocument();
        marshaller.marshal( registerResult, registerResultDoc );

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        XMLUtils.outputDOM(registerResultDoc, baos);
        log.debug("XMLUtils.outputDOM: " + baos.toString());
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());

        JAXBElement<RegisterResultType> registerResult2 = (JAXBElement<RegisterResultType>) unmarshaller.unmarshal(bais);
        registerResultType = registerResult2.getValue();
       
        PrivateKeyType privateKeyType2 = registerResultType.getPrivateKey();
        RSAPrivateKey privkey2 = XKMSUtil.getPrivateKeyFromEncryptedXML(privateKeyType2, "This is total crap");
        X509Certificate cert = CertTools.genSelfCert("CN=test", 10, null,privkey2, keys.getPublic(), "SHA1WithRSA", true);
        cert.verify(keys.getPublic());   
    }   
View Full Code Here

 
  /**
   * Returns a register response
   */
  public RegisterResultType getResponse(boolean requestVerifies){
    RegisterResultType result = xkmsFactory.createRegisterResultType();   
    super.populateResponse(result, requestVerifies);   
    RegisterRequestType req = (RegisterRequestType) this.req;

    if(resultMajor == null){    
      if(!checkValidRespondWithRequest(req.getRespondWith(),false)){
        resultMajor = XKMSConstants.RESULTMAJOR_SENDER;
        resultMinor = XKMSConstants.RESULTMINOR_MESSAGENOTSUPPORTED;
      }
      if(resultMajor == null){
        if(resultMajor == null){   // TODO: Bug??
          PublicKey publicKey = getPublicKey(req);         
          if(confirmPOP(publicKey)){
            String subjectDN = getSubjectDN(req);
            UserDataVO userData = findUserData(subjectDN);
            if(userData != null){
              String password = ""
              boolean encryptedPassword = isPasswordEncrypted(req);
              if(encryptedPassword){
                password = getEncryptedPassword(requestDoc, userData.getPassword());
              }else{
                password = getClearPassword(req, userData.getPassword());
              }
              String revocationCode = getRevocationCode(req);
              if(password != null ){
                X509Certificate cert = registerReissueOrRecover(false,false, result, userData,password, publicKey, revocationCode);
                if(cert != null){
                  KeyBindingAbstractType keyBinding = getResponseValues(req.getPrototypeKeyBinding(), cert, false, true);
                  result.getKeyBinding().add((KeyBindingType) keyBinding);
                }
              }
            }
          }
        }
View Full Code Here

                outputPath = args[ARG_OUTPUTPATH] + "/";                           
              }
            }

            String reqId = genId();
            ReissueRequestType reissueRequestType = xKMSObjectFactory.createReissueRequestType();
            reissueRequestType.setId(reqId);
            reissueRequestType.getRespondWith().add(XKMSConstants.RESPONDWITH_X509CHAIN);
           
            String keyBindingId =  "_" + orgCert.getSerialNumber().toString();
            X509DataType x509DataType = sigFactory.createX509DataType();
            x509DataType.getX509IssuerSerialOrX509SKIOrX509SubjectName().add(sigFactory.createX509DataTypeX509Certificate(orgCert.getEncoded()));
            KeyInfoType keyInfoType = sigFactory.createKeyInfoType();
            keyInfoType.getContent().add(sigFactory.createX509Data(x509DataType));
           
            KeyBindingType keyBindingType = xKMSObjectFactory.createKeyBindingType();               
            keyBindingType.setKeyInfo(keyInfoType);
            keyBindingType.setId(keyBindingId);
            reissueRequestType.setReissueKeyBinding(keyBindingType);   
                              
            PrivateKey privateKey = (PrivateKey) ks.getKey(alias, keyPass.toCharArray());
            ReissueResultType reissueResultType = getXKMSInvoker().reissue(reissueRequestType, clientCert, privateKey, authPass, privateKey, keyBindingId);           
            
            if(reissueResultType.getResultMajor().equals(XKMSConstants.RESULTMAJOR_SUCCESS) &&
View Full Code Here

   * Returns a reissue response
   */
  public ReissueResultType getResponse(boolean requestVerifies){
    ReissueResultType result = xkmsFactory.createReissueResultType();   
    super.populateResponse(result, requestVerifies);   
    ReissueRequestType req = (ReissueRequestType) this.req;
    // Variables defined here for debug reasons
    boolean isCertValid=false;
    UserDataVO userData = null;
    String password = "";
    X509Certificate newCert = null;
    if(resultMajor == null){    
      if(!checkValidRespondWithRequest(req.getRespondWith(),false)){
        resultMajor = XKMSConstants.RESULTMAJOR_SENDER;
        resultMinor = XKMSConstants.RESULTMINOR_MESSAGENOTSUPPORTED;
      }
      if(resultMajor == null){
        if(resultMajor == null){
          X509Certificate cert = (X509Certificate) getPublicKeyInfo(req, false);
          isCertValid = certIsValid(cert);
          if(isCertValid && confirmPOP(cert.getPublicKey())){           
            userData = findUserData(cert);
            if(userData != null){
              boolean encryptedPassword = isPasswordEncrypted(req);
              if(isCertValid && XKMSConfig.isAutomaticReissueAllowed()){
                password = setUserStatusToNew(userData);
              }else{             
                if(encryptedPassword){
                  password = getEncryptedPassword(requestDoc, userData.getPassword());
                }else{
                  password = getClearPassword(req, userData.getPassword());
                }
              }
              if(password != null ){
                newCert = registerReissueOrRecover(false,true, result, userData,password, cert.getPublicKey(), null);
                if(newCert != null){
                  KeyBindingAbstractType keyBinding = getResponseValues(req.getReissueKeyBinding(), newCert, false, true);
                  result.getKeyBinding().add((KeyBindingType) keyBinding);
                }
              }
            }
          }
View Full Code Here

TOP

Related Classes of org.w3._2002._03.xkms_.RequestAbstractType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.