Private method for parsing keystore entry.

@throws throws Exception when any problem occurred during parsing keystore entry
513774
private void parseKeystore() throws Exception {
        String tempKeystoreURL = null;
        String tempKeystoreType = null;
        String tempKeystoreProvider = null;
        lookahead = st.nextToken();
        if (lookahead == '\"') {
            tempKeystoreURL = st.sval;
        } else {
            throw new Exception("ER029: [\"keystore_URL\"] expected.");
        }

        lookahead = st.nextToken();
        if (lookahead == ',') {
            lookahead = st.nextToken();
            if (lookahead == '\"') {
                tempKeystoreType = st.sval;
            } else {
                throw new Exception("ER030: [\"keystore_type\"] expected.");
            }
            lookahead = st.nextToken();
            if (lookahead == ',') {
                lookahead = st.nextToken();
                if (lookahead == '\"') {
                    tempKeystoreProvider = st.sval;
                } else {
                    throw new Exception("ER031: [\"keystore_provider\"] expected.");
                }
                lookahead = st.nextToken();
            }
        }

        if (lookahead == ';') {
            if (keystoreEntry == null) {
                keystoreEntry = new ParsedKeystoreEntry(tempKeystoreURL, tempKeystoreType, tempKeystoreProvider);
            }
        } else {
            throw new Exception("ER032: [;] expected at the end of keystore entry.");
        }
    }
866959
public void provideExpirationWarnings(int daysBeforeExpireWarning, String keyStoreName) throws Exception {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.entry(tc, "provideExpirationWarnings", Integer.valueOf(daysBeforeExpireWarning));

        KeyStore keystore = getKeyStore(false, false);

        if (keystore != null) {
            try {
                Enumeration<String> e = keystore.aliases();
                if (e != null) {
                    for (; e.hasMoreElements();) {
                        String alias = e.nextElement();
                        if (null == alias)
                            continue;
                        Certificate[] cert_chain = keystore.getCertificateChain(alias);
                        if (null == cert_chain)
                            continue;
                        for (int i = 0; i < cert_chain.length; i++) {
                            printWarning(daysBeforeExpireWarning, keyStoreName, alias, (X509Certificate) cert_chain[i]);
                        }
                    }
                }
            } catch (Exception e) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    Tr.debug(tc, "Exception validating KeyStore expirations; " + e);
                FFDCFilter.processException(e, getClass().getName(), "provideExpirationWarnings", this);
                throw e;
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.exit(tc, "provideExpirationWarnings");
    }
74810
protected function getAESKey()
    {
        if (empty($this->AESKey)) {
            throw new Exception("Configuration mission, 'aes_key' is required.");
        }

        if (strlen($this->AESKey) !== 43) {
            throw new Exception("The length of 'aes_key' must be 43.");
        }

        return base64_decode($this->AESKey . '=', true);
    }
220363
public void checkKeyStore() {
        if (sslContext != null)
            return; //nothing to check if using preconfigured context
        
        if (keyStoreInputStream == null &&
	    sslConfig.getKeyStorePath() == null) {
            throw new IllegalStateException("SSL doesn't have a valid keystore");
        }
        // if the keystore has been configured but there is no
        // truststore configured, use the keystore as the truststore
        if (trustStoreInputStream == null && sslConfig.getTrustStorePath() == null) {
            trustStoreInputStream = keyStoreInputStream;
            sslConfig.setTrustStorePath(sslConfig.getKeyStorePath());
            sslConfig.setTrustStoreType(sslConfig.getKeyStoreType());
            sslConfig.setTrustStoreProvider(sslConfig.getKeyStoreProvider());
            sslConfig.setTrustStorePassword(sslConfig.getKeyStorePassword());
            sslConfig.setTrustManagerFactoryAlgorithm(sslConfig.getKeyManagerFactoryAlgorithm());
        }

        // It's the same stream we cannot read it twice, so read it once in memory
        if (keyStoreInputStream != null && keyStoreInputStream == trustStoreInputStream) {
            try {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
		streamCopy(keyStoreInputStream, baos, null, false);
                keyStoreInputStream.close();
                keyStoreInputStream = new ByteArrayInputStream(baos.toByteArray());
                trustStoreInputStream = new ByteArrayInputStream(baos.toByteArray());
            } catch (Exception ex) {
                throw new IllegalStateException(ex);
            }
        }
    }
1132810
public function parse()
    {
        // Split up the TAP string into an array of lines, then
        // trim all of the lines so there's no leading or trailing whitespace.
        $this->lines = array_map('rtrim', explode("\n", $this->tapString));
        $this->lineNumber = 0;

        $this->testCount = false;
        $this->results = array();

        $header = $this->findTapLog();

        $line = $this->nextLine();
        if ($line === $header) {
            throw new Exception("Duplicated TAP log, please check the configuration.");
        }

        while ($line !== false && ($this->testCount === false || count($this->results) < $this->testCount)) {
            $this->parseLine($line);
            $line = $this->nextLine();
        }

        if (false !== $this->testCount && count($this->results) !== $this->testCount) {
            throw new Exception(Lang::get('tap_error'));
        }

        return $this->results;
    }
97226
private SSLConfig parseSSLConfig(Map<String, Object> properties, boolean reinitialize) throws Exception {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.entry(tc, "parseSSLConfig: " + properties.get(LibertyConstants.KEY_ID), properties);

        SSLConfig rc = parseSecureSocketLayer(properties, reinitialize);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.exit(tc, "parseSSLConfig");
        return rc;
    }
43539
private void parseElementDecl() throws Exception {
        String name;

        requireWhitespace();
        // Read the element type name.
        name = readNmtoken(true);

        requireWhitespace();
        // Read the content model.
        parseContentspec(name);

        skipWhitespace();
        require('>');
    }
475091
public static void parseCommonStoreAttributes(XMLExtendedStreamReader reader, StoreConfigurationBuilder builder, String attributeName, String value, int i) throws XMLStreamException {
      switch (Attribute.forName(attributeName)) {
         case FETCH_PERSISTENT_STATE:
            builder.fetchPersistentState(Boolean.valueOf(value));
            break;
         case IGNORE_MODIFICATIONS:
            builder.ignoreModifications(Boolean.valueOf(value));
            break;
         case PURGE_ON_STARTUP:
            builder.purgeOnStartup(Boolean.valueOf(value));
            break;
         case PRELOAD:
            builder.preload(Boolean.parseBoolean(value));
            break;
         case SHARED:
            builder.shared(Boolean.parseBoolean(value));
            break;
         default:
            throw ParseUtils.unexpectedAttribute(reader, i);
      }
   }
71010
public void doAESEncryption() throws Exception{
		if(!initAESDone)
			initAES();
		cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
		//System.out.println(secretKey.getEncoded());
		cipher.init(Cipher.ENCRYPT_MODE, secretKey);
		AlgorithmParameters params = cipher.getParameters();
		iv = params.getParameterSpec(IvParameterSpec.class).getIV();
		secretCipher = cipher.doFinal(secretPlain);
		clearPlain();
	}
137318
private function parseKey()
    {
        $parts = explode('.', $this->argument('key'), 2);

        $this->file = $parts[0];

        $this->key = isset($parts[1]) ? $parts[1] : null;

        if (Str::contains($this->file, '::')) {
            try {
                $parts = explode('::', $this->file);

                $this->manager->setPathToVendorPackage($parts[0]);
            } catch (\ErrorException $e) {
                $this->error('Could not recognize the package.');

                return;
            }
        }
    }
767959
public void addKeyStoreToMap(String keyStoreName, WSKeyStore ks) throws Exception {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.entry(tc, "addKeyStoreToMap: " + keyStoreName + ", ks=" + ks);

        if (keyStoreMap.containsKey(keyStoreName))
            keyStoreMap.remove(keyStoreName);
        keyStoreMap.put(keyStoreName, ks);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.exit(tc, "addKeyStoreToMap");
    }
131986
@Override
    protected void parse() {
		getConnectionParam().load(getConfig());
	    getProxyParam().load(getConfig());
		getCertificateParam().load(getConfig());
		getViewParam().load(getConfig());
		getCheckForUpdatesParam().load(getConfig());
		getApiParam().load(getConfig());
		getGlobalExcludeURLParam().load(getConfig());
		getExperimentalFeaturesParam().load(getConfig());
        getDatabaseParam().load(getConfig());
        getExtensionParam().load(getConfig());
		
		String userDir = null;
		try {
			userDir = getConfig().getString(USER_DIR);
			if (userDir != null) {
				this.userDirectory = new File(userDir);
			}
		} catch (Exception e) {
			// In a previous release the userdir was set as a file
			try {
				File file = (File) getConfig().getProperty(USER_DIR);
				if (file != null && file.isDirectory()) {
					this.userDirectory = file;
				}
			} catch (Exception e1) {
				logger.error(e1.getMessage(), e1);
			}
		}
    }
700610
private void parse()
    {
        this.elements = new ArrayList<>();

        try {
            for (Tokenizer tokenizer = new Tokenizer(this.rawVersion); tokenizer.next();) {
                Element element = new Element(tokenizer);
                this.elements.add(element);
                if (element.getVersionType() != Type.STABLE) {
                    this.type = element.getVersionType();
                }
            }

            trimPadding(this.elements);
        } catch (Exception e) {
            // Make sure to never fail no matter what
            LOGGER.error("Failed to parse version [" + this.rawVersion + "]", e);
            this.elements.add(new Element(this.rawVersion));
        }
    }
809309
public void parse () throws JsonParseException
  {
    _readValue ();

    // Check for trailing whitespaces
    _skipSpaces ();

    final IJsonParsePosition aStartPos = m_aPos.getClone ();

    // Check for expected end of input
    final int c = _readChar ();
    if (c != EOI)
      throw _parseEx (aStartPos, "Invalid character " + _getPrintableChar (c) + " after JSON root object");
  }
872964
public void store() throws Exception {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.entry(tc, "store");

        try {
            String name = getProperty(Constants.SSLPROP_KEY_STORE_NAME);
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                Tr.debug(tc, "Storing KeyStore " + name);

            String SSLKeyFile = getProperty(Constants.SSLPROP_KEY_STORE);
            String SSLKeyPassword = decodePassword(getProperty(Constants.SSLPROP_KEY_STORE_PASSWORD));
            String SSLKeyStoreType = getProperty(Constants.SSLPROP_KEY_STORE_TYPE);

            boolean readOnly = Boolean.parseBoolean(getProperty(Constants.SSLPROP_KEY_STORE_READ_ONLY));
            boolean fileBased = Boolean.parseBoolean(getProperty(Constants.SSLPROP_KEY_STORE_FILE_BASED));
            String SSLKeyStoreStash = getProperty(Constants.SSLPROP_KEY_STORE_CREATE_CMS_STASH);

            KeyStore ks = getKeyStore(false, false);

            if (ks != null && !readOnly) {
                if (fileBased) {
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                        Tr.debug(tc, "Storing filebased keystore type " + SSLKeyStoreType);
                    String keyStoreLocation = SSLKeyFile;
                    String keyStorePassword = SSLKeyPassword;
                    final FileOutputStream fos = new FileOutputStream(keyStoreLocation);
                    try {
                        ks.store(fos, keyStorePassword.toCharArray());
                    } finally {
                        fos.close();
                    }
                } else {
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                        Tr.debug(tc, "Storing non-filebased keystore type " + SSLKeyStoreType);
                    String keyStoreLocation = SSLKeyFile;
                    String keyStorePassword = SSLKeyPassword;
                    URL ring = new URL(keyStoreLocation);
                    URLConnection ringConnect = ring.openConnection();
                    final OutputStream fos = ringConnect.getOutputStream();
                    try {
                        ks.store(fos, keyStorePassword.toCharArray());
                    } finally {
                        fos.close();
                    }
                }
            }

            // we will likely have to store other types too
        } catch (Exception e) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                Tr.debug(tc, "Exception storing KeyStore; " + e);
            FFDCFilter.processException(e, getClass().getName(), "store", this);
            throw e;
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.exit(tc, "store");
    }
1260102
public static void main(String[] args) throws Exception {

        // Generate public/private key pair
        KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
        keyGen.initialize(2048);
        KeyPair pair = keyGen.generateKeyPair();
        java.security.PublicKey pk = pair.getPublic();

        // Use the default rest client
        TwilioRestClient client =
            new TwilioRestClient.Builder(ACCOUNT_SID, AUTH_TOKEN)
                .build();

        // Create a public key and signing key using the default client
        PublicKey key = PublicKey.creator(
            Base64.encodeBase64String(pk.getEncoded())
        ).setFriendlyName("Public Key").create(client);

        NewSigningKey signingKey = NewSigningKey.creator().create(client);

        // Switch to validation client as the default client
        TwilioRestClient validationClient = new TwilioRestClient.Builder(signingKey.getSid(), signingKey.getSecret())
            .accountSid(ACCOUNT_SID)
            .httpClient(new ValidationClient(ACCOUNT_SID, key.getSid(), signingKey.getSid(), pair.getPrivate()))
            .build();

        // Make REST API requests
        Iterable<Message> messages = Message.reader().read(validationClient);
        for (Message message : messages) {
            System.out.println(message.getBody());
        }

        Message message = Message.creator(
            new PhoneNumber("+1XXXXXXXXXX"),
            new PhoneNumber("+1XXXXXXXXXX"),
            "Public Key Client Validation Test"
        ).create(validationClient);
        System.out.println(message.getSid());
    }
1077956
public void validate( KeyStore keyStore ) throws CertificateException
{
    try
    {
        Enumeration<String> aliases = keyStore.aliases();
        
        for ( ; aliases.hasMoreElements(); )
        {
            String alias = aliases.nextElement();
            
            validate(keyStore,alias);
        }
        
    }
    catch ( KeyStoreException kse )
    {
        throw new CertificateException("Unable to retrieve aliases from keystore", kse);
    }
}