private void loadDefaultKey(String signingKeyFile, String signingKeyName) { BasicOAuthStoreConsumerKeyAndSecret key = null; if (!StringUtils.isBlank(signingKeyFile)) { try { if (LOG.isLoggable(Level.INFO)) { LOG.logp(Level.INFO, classname, "loadDefaultKey", MessageKeys.LOAD_KEY_FILE_FROM, new Object[] {signingKeyFile}); } String privateKey = IOUtils.toString(ResourceLoader.open(signingKeyFile), "UTF-8"); privateKey = BasicOAuthStore.convertFromOpenSsl(privateKey); key = new BasicOAuthStoreConsumerKeyAndSecret(null, privateKey, KeyType.RSA_PRIVATE, signingKeyName, null); } catch (Throwable t) { if (LOG.isLoggable(Level.WARNING)) { LOG.logp(Level.WARNING, classname, "loadDefaultKey", MessageKeys.COULD_NOT_LOAD_KEY_FILE, new Object[] {signingKeyFile}); LOG.logp(Level.WARNING, classname, "loadDefaultKey", "",t); } } } if (key != null) { store.setDefaultKey(key); } else { if (LOG.isLoggable(Level.WARNING)) { LOG.logp(Level.WARNING, classname, "loadDefaultKey", MessageKeys.COULD_NOT_LOAD_SIGN_KEY, new Object[] {OAUTH_SIGNING_KEY_FILE,OAUTH_SIGNING_KEY_NAME}); } } }
private void loadDefaultKey(String signingKeyFile, String signingKeyName) { BasicOAuthStoreConsumerKeyAndSecret key = null; if (!StringUtils.isBlank(signingKeyFile)) { try { LOG.info("Loading OAuth signing key from " + signingKeyFile); String privateKey = IOUtils.toString(ResourceLoader.open(signingKeyFile), "UTF-8"); privateKey = BasicOAuthStore.convertFromOpenSsl(privateKey); key = new BasicOAuthStoreConsumerKeyAndSecret(null, privateKey, KeyType.RSA_PRIVATE, signingKeyName, null); } catch (Throwable t) { LOG.log(Level.WARNING, "Couldn't load key file " + signingKeyFile, t); } } if (key != null) { store.setDefaultKey(key); } else { LOG.log(Level.WARNING, "Couldn't load OAuth signing key. To create a key, run:\n" + " openssl req -newkey rsa:1024 -days 365 -nodes -x509 -keyout testkey.pem \\\n" + " -out testkey.pem -subj '/CN=mytestkey'\n" + " openssl pkcs8 -in testkey.pem -out oauthkey.pem -topk8 -nocrypt -outform PEM\n" + '\n' + "Then edit shindig.properties and add these lines:\n" + OAUTH_SIGNING_KEY_FILE + "=<path-to-oauthkey.pem>\n" + OAUTH_SIGNING_KEY_NAME + "=mykey\n"); } }
private void realStoreConsumerInfo(URI gadgetUri, String serviceName, JSONObject consumerInfo) throws JSONException { String callbackUrl = consumerInfo.optString(CALLBACK_URL, null); String consumerSecret = consumerInfo.getString(CONSUMER_SECRET_KEY); String consumerKey = consumerInfo.getString(CONSUMER_KEY_KEY); String keyTypeStr = consumerInfo.getString(KEY_TYPE_KEY); KeyType keyType = KeyType.HMAC_SYMMETRIC; if ("RSA_PRIVATE".equals(keyTypeStr)) { keyType = KeyType.RSA_PRIVATE; consumerSecret = convertFromOpenSsl(consumerSecret); } BasicOAuthStoreConsumerKeyAndSecret kas = new BasicOAuthStoreConsumerKeyAndSecret( consumerKey, consumerSecret, keyType, null, callbackUrl); BasicOAuthStoreConsumerIndex index = new BasicOAuthStoreConsumerIndex(); index.setGadgetUri(gadgetUri.toASCIIString()); index.setServiceName(serviceName); setConsumerKeyAndSecret(index, kas); }
private void loadDefaultKey(String signingKeyFile, String signingKeyName) { BasicOAuthStoreConsumerKeyAndSecret key = null; if (!StringUtils.isBlank(signingKeyFile)) { try { LOG.info("Loading OAuth signing key from " + signingKeyFile); String privateKey = IOUtils.toString(ResourceLoader.open(signingKeyFile), "UTF-8"); privateKey = BasicOAuthStore.convertFromOpenSsl(privateKey); key = new BasicOAuthStoreConsumerKeyAndSecret(null, privateKey, KeyType.RSA_PRIVATE, signingKeyName, null); } catch (Throwable t) { LOG.log(Level.WARNING, "Couldn't load key file " + signingKeyFile, t); } } if (key != null) { store.setDefaultKey(key); } else { LOG.log(Level.WARNING, "Couldn't load OAuth signing key. To create a key, run:\n" + " openssl req -newkey rsa:1024 -days 365 -nodes -x509 -keyout testkey.pem \\\n" + " -out testkey.pem -subj '/CN=mytestkey'\n" + " openssl pkcs8 -in testkey.pem -out oauthkey.pem -topk8 -nocrypt -outform PEM\n" + '\n' + "Then edit shindig.properties and add these lines:\n" + OAUTH_SIGNING_KEY_FILE + "=<path-to-oauthkey.pem>\n" + OAUTH_SIGNING_KEY_NAME + "=mykey\n"); } }
private void realStoreConsumerInfo(URI gadgetUri, String serviceName, JSONObject consumerInfo) throws JSONException { String callbackUrl = consumerInfo.optString(CALLBACK_URL, null); String consumerSecret = consumerInfo.getString(CONSUMER_SECRET_KEY); String consumerKey = consumerInfo.getString(CONSUMER_KEY_KEY); String keyTypeStr = consumerInfo.getString(KEY_TYPE_KEY); KeyType keyType = KeyType.HMAC_SYMMETRIC; if ("RSA_PRIVATE".equals(keyTypeStr)) { keyType = KeyType.RSA_PRIVATE; consumerSecret = convertFromOpenSsl(consumerSecret); } BasicOAuthStoreConsumerKeyAndSecret kas = new BasicOAuthStoreConsumerKeyAndSecret( consumerKey, consumerSecret, keyType, null, callbackUrl); BasicOAuthStoreConsumerIndex index = new BasicOAuthStoreConsumerIndex(); index.setGadgetUri(gadgetUri.toASCIIString()); index.setServiceName(serviceName); setConsumerKeyAndSecret(index, kas); }
private void realStoreConsumerInfo(URI gadgetUri, String serviceName, JSONObject consumerInfo) throws JSONException { String callbackUrl = consumerInfo.optString(CALLBACK_URL, null); String consumerSecret = consumerInfo.getString(CONSUMER_SECRET_KEY); String consumerKey = consumerInfo.getString(CONSUMER_KEY_KEY); String keyTypeStr = consumerInfo.getString(KEY_TYPE_KEY); boolean oauthBodyHash = true; String oauthBodyHashString = consumerInfo.optString(OAUTH_BODY_HASH_KEY); if ("false".equalsIgnoreCase(oauthBodyHashString)) { oauthBodyHash = false; } KeyType keyType = KeyType.HMAC_SYMMETRIC; if ("RSA_PRIVATE".equals(keyTypeStr)) { keyType = KeyType.RSA_PRIVATE; consumerSecret = convertFromOpenSsl(consumerSecret); } else if ("PLAINTEXT".equals(keyTypeStr)) { keyType = KeyType.PLAINTEXT; } BasicOAuthStoreConsumerKeyAndSecret kas = new BasicOAuthStoreConsumerKeyAndSecret( consumerKey, consumerSecret, keyType, null, callbackUrl, oauthBodyHash); BasicOAuthStoreConsumerIndex index = new BasicOAuthStoreConsumerIndex(); index.setGadgetUri(gadgetUri.toASCIIString()); index.setServiceName(serviceName); setConsumerKeyAndSecret(index, kas); }