public void handle(URLConnection connection) throws Exception { // TODO switch to https since this signing is only secure with https // since we only sign the date. if (!(connection instanceof HttpURLConnection) || !matches(connection)) return; if (!(connection instanceof HttpsURLConnection)) trace("bnd authentication should only be used with https: %s", connection.getURL()); init(); // Build up Authorization header StringBuilder sb = new StringBuilder(identity); // Get the date header, set it if not set String dateHeader = connection.getRequestProperty("Date"); if (dateHeader == null) { synchronized (httpFormat) { dateHeader = httpFormat.format(new Date()); } connection.setRequestProperty("Date", dateHeader); } // Ok, calculate the signature Signature hmac = Signature.getInstance("SHA1withRSA"); hmac.initSign(privateKey); hmac.update(dateHeader.getBytes()); // never non-ascii // Finish the header sb.append(Base64.encodeBase64(hmac.sign())); connection.setRequestProperty(X_A_QUTE_AUTHORIZATION, sb.toString()); }
@Override public void handle(URLConnection connection) throws Exception { // TODO switch to https since this signing is only secure with https // since we only sign the date. if (!(connection instanceof HttpURLConnection) || !matches(connection)) return; if (!(connection instanceof HttpsURLConnection)) logger.debug("bnd authentication should only be used with https: {}", connection.getURL()); init(); // Build up Authorization header StringBuilder sb = new StringBuilder(identity); // Get the date header, set it if not set String dateHeader = connection.getRequestProperty("Date"); if (dateHeader == null) { synchronized (httpFormat) { dateHeader = httpFormat.format(new Date()); } connection.setRequestProperty("Date", dateHeader); } // Ok, calculate the signature Signature hmac = Signature.getInstance("SHA1withRSA"); hmac.initSign(privateKey); hmac.update(dateHeader.getBytes()); // never non-ascii // Finish the header sb.append(Base64.encodeBase64(hmac.sign())); connection.setRequestProperty(X_A_QUTE_AUTHORIZATION, sb.toString()); }
@Override public void setProperties(Map<String, String> map) throws Exception { super.setProperties(map); String email = map.get(EMAIL); if (email == null) { Settings settings = registry.getPlugin(Settings.class); email = settings.getEmail(); if (email == null) { error( "The bnd authentication URL connection handler has no email set as property, nor have the bnd settings been set"); return; } credentials(email, settings.getPublicKey(), settings.getPrivateKey()); } else { String pub = map.get(PUBLIC_KEY); String prv = map.get(PRIVATE_KEY); if (pub == null || !Hex.isHex(pub)) { error("The bnd authentication URL public key for email %s is not a hex string %s", email, pub); return; } if (prv == null || !Hex.isHex(prv)) { error("The bnd authentication URL private key for email %s is not a hex string", email); return; } credentials(email, Hex.toByteArray(pub), Hex.toByteArray(prv)); } machine = map.get(MACHINE); }
@Override public void setProperties(Map<String, String> map) throws Exception { super.setProperties(map); String email = map.get(EMAIL); if (email == null) { Settings settings = registry.getPlugin(Settings.class); email = settings.getEmail(); if (email == null) { error( "The bnd authentication URL connection handler has no email set as property, nor have the bnd settings been set"); return; } credentials(email, settings.getPublicKey(), settings.getPrivateKey()); } else { String pub = map.get(PUBLIC_KEY); String prv = map.get(PRIVATE_KEY); if (pub == null || !Hex.isHex(pub)) { error("The bnd authentication URL public key for email %s is not a hex string %s", email, pub); return; } if (prv == null || !Hex.isHex(prv)) { error("The bnd authentication URL private key for email %s is not a hex string", email); return; } credentials(email, Hex.toByteArray(pub), Hex.toByteArray(prv)); } machine = map.get(MACHINE); }
@Override public void handle(URLConnection connection) throws Exception { // TODO switch to https since this signing is only secure with https // since we only sign the date. if (!(connection instanceof HttpURLConnection) || !matches(connection)) return; if (!(connection instanceof HttpsURLConnection)) logger.debug("bnd authentication should only be used with https: {}", connection.getURL()); init(); // Build up Authorization header StringBuilder sb = new StringBuilder(identity); // Get the date header, set it if not set String dateHeader = connection.getRequestProperty("Date"); if (dateHeader == null) { synchronized (httpFormat) { dateHeader = httpFormat.format(new Date()); } connection.setRequestProperty("Date", dateHeader); } // Ok, calculate the signature Signature hmac = Signature.getInstance("SHA1withRSA"); hmac.initSign(privateKey); hmac.update(dateHeader.getBytes()); // never non-ascii // Finish the header sb.append(Base64.encodeBase64(hmac.sign())); connection.setRequestProperty(X_A_QUTE_AUTHORIZATION, sb.toString()); }
@Override public void setProperties(Map<String,String> map) throws Exception { super.setProperties(map); String email = map.get(EMAIL); if (email == null) { Workspace ws = registry.getPlugin(Workspace.class); Settings settings = registry.getPlugin(Settings.class); email = settings.getEmail(); if (email == null) { error("The bnd authentication URL connection handler has no email set as property, nor have the bnd settings been set"); return; } credentials(email, settings.getPublicKey(), settings.getPrivateKey()); } else { String pub = map.get(PUBLIC_KEY); String prv = map.get(PRIVATE_KEY); if (pub == null || !Hex.isHex(pub)) { error("The bnd authentication URL public key for email %s is not a hex string %s", email, pub); return; } if (prv == null || !Hex.isHex(prv)) { error("The bnd authentication URL private key for email %s is not a hex string", email); return; } credentials(email, Hex.toByteArray(pub), Hex.toByteArray(prv)); } machine = map.get(MACHINE); }
public void handle(URLConnection connection) throws Exception { // TODO switch to https since this signing is only secure with https // since we only sign the date. if (!(connection instanceof HttpURLConnection) || !matches(connection)) return; if (!(connection instanceof HttpsURLConnection)) trace("bnd authentication should only be used with https: %s", connection.getURL()); init(); // Build up Authorization header StringBuilder sb = new StringBuilder(identity); // Get the date header, set it if not set String dateHeader = connection.getRequestProperty("Date"); if (dateHeader == null) { synchronized (httpFormat) { dateHeader = httpFormat.format(new Date()); } connection.setRequestProperty("Date", dateHeader); } // Ok, calculate the signature Signature hmac = Signature.getInstance("SHA1withRSA"); hmac.initSign(privateKey); hmac.update(dateHeader.getBytes()); // never non-ascii // Finish the header sb.append(Base64.encodeBase64(hmac.sign())); connection.setRequestProperty(X_A_QUTE_AUTHORIZATION, sb.toString()); }
@Override public void setProperties(Map<String,String> map) throws Exception { super.setProperties(map); String email = map.get(EMAIL); if (email == null) { Workspace ws = registry.getPlugin(Workspace.class); Settings settings = registry.getPlugin(Settings.class); email = settings.getEmail(); if (email == null) { error("The bnd authentication URL connection handler has no email set as property, nor have the bnd settings been set"); return; } credentials(email, settings.getPublicKey(), settings.getPrivateKey()); } else { String pub = map.get(PUBLIC_KEY); String prv = map.get(PRIVATE_KEY); if (pub == null || !Hex.isHex(pub)) { error("The bnd authentication URL public key for email %s is not a hex string %s", email, pub); return; } if (prv == null || !Hex.isHex(prv)) { error("The bnd authentication URL private key for email %s is not a hex string", email); return; } credentials(email, Hex.toByteArray(pub), Hex.toByteArray(prv)); } machine = map.get(MACHINE); }