Package java.net

Examples of java.net.MalformedURLException


  public static InsertableClientSSK create(FreenetURI uri) throws MalformedURLException {
    if(uri.getKeyType().equalsIgnoreCase("KSK"))
      return ClientKSK.create(uri);

    if(uri.getRoutingKey() == null)
      throw new MalformedURLException("Insertable SSK URIs must have a private key!: "+uri);
    if(uri.getCryptoKey() == null)
      throw new MalformedURLException("Insertable SSK URIs must have a private key!: "+uri);
   
    byte keyType;

    byte[] extra = uri.getExtra();
    if(uri.getKeyType().equals("SSK")) {
      if(extra == null)
        throw new MalformedURLException("Inserting pre-1010 keys not supported");
      // Formatted exactly as ,extra on fetching
      if(extra.length < 5)
        throw new MalformedURLException("SSK private key ,extra too short");
      if(extra[1] != 1) {
        throw new MalformedURLException("SSK not a private key");
      }
      keyType = extra[2];
      if(keyType != Key.ALGO_AES_PCFB_256_SHA256)
        throw new MalformedURLException("Unrecognized crypto type in SSK private key");
    }
    else {
      throw new MalformedURLException("Not a valid SSK insert URI type: "+uri.getKeyType());
    }
   
    // Allow docName="" for SSKs. E.g. GenerateSSK returns these; we want to be consistent.
    // However, we recommend that you not use this, especially not for a freesite, as
    // SSK@blah,blah,blah//filename is confusing for clients, browsers etc.
    if(uri.getDocName() == null)
      throw new MalformedURLException("SSK URIs must have a document name (to avoid ambiguity)");
    DSAGroup g = Global.DSAgroupBigA;
    DSAPrivateKey privKey;
    try {
      privKey = new DSAPrivateKey(new NativeBigInteger(1, uri.getRoutingKey()), g);
    } catch(IllegalArgumentException e) {
      // DSAPrivateKey is invalid
      Logger.error(InsertableClientSSK.class, "Caught "+e, e);
      throw new MalformedURLException("SSK private key (routing key) is invalid: " + e);
    }
    DSAPublicKey pubKey = new DSAPublicKey(g, privKey);
    byte[] pkHash = pubKey.asBytesHash();
    return new InsertableClientSSK(uri.getDocName(), pkHash, pubKey, privKey, uri.getCryptoKey(), keyType);
  }
View Full Code Here


    this.pubKeyHash = pubKeyHash;
    this.cryptoKey = cryptoKey;
    this.siteName = siteName;
    this.suggestedEdition = suggestedEdition;
    if(extra == null)
      throw new MalformedURLException("No extra bytes (third bit) in USK");
    if(pubKeyHash == null)
      throw new MalformedURLException("No pubkey hash (first bit) in USK");
    if(cryptoKey == null)
      throw new MalformedURLException("No crypto key (second bit) in USK");
    // Verify extra bytes, get cryptoAlgorithm - FIXME this should be a static method or something?
    ClientSSK tmp = new ClientSSK(siteName, pubKeyHash, extra, null, cryptoKey);
    cryptoAlgorithm = tmp.cryptoAlgorithm;
    if(pubKeyHash.length != NodeSSK.PUBKEY_HASH_SIZE)
      throw new MalformedURLException("Pubkey hash wrong length: "+pubKeyHash.length+" should be "+NodeSSK.PUBKEY_HASH_SIZE);
    if(cryptoKey.length != ClientSSK.CRYPTO_KEY_LENGTH)
      throw new MalformedURLException("Decryption key wrong length: "+cryptoKey.length+" should be "+ClientSSK.CRYPTO_KEY_LENGTH);
    hashCode = Fields.hashCode(pubKeyHash) ^ Fields.hashCode(cryptoKey) ^
      siteName.hashCode() ^ (int)suggestedEdition ^ (int)(suggestedEdition >> 32);
  }
View Full Code Here

    hashCode = Fields.hashCode(pubKeyHash) ^ Fields.hashCode(cryptoKey) ^
      siteName.hashCode() ^ (int)suggestedEdition ^ (int)(suggestedEdition >> 32);
  }

  public static USK create(FreenetURI uri) throws MalformedURLException {
    if(!uri.isUSK()) throw new MalformedURLException("Not a USK");
    return new USK(uri.getRoutingKey(), uri.getCryptoKey(), uri.getExtra(), uri.getDocName(), uri.getSuggestedEdition());
  }
View Full Code Here

    if(fullKeys) {
      freenetURI.writeFullBinaryKeyWithLength(dos);
    } else {
      String[] meta = freenetURI.getAllMetaStrings();
      if((meta != null) && (meta.length > 0))
        throw new MalformedURLException("Not a plain CHK");
      BaseClientKey key = BaseClientKey.getBaseKey(freenetURI);
      if(key instanceof ClientCHK) {
        ((ClientCHK)key).writeRawBinaryKey(dos);
      } else throw new IllegalArgumentException("Full keys must be enabled to write non-CHKs");
    }
View Full Code Here

    }

    private static URL makeIconFileURL(final String iconPath)
            throws MalformedURLException {
        if (ICON_BASE_URL == null) {
            throw new MalformedURLException();
        }

        return new URL(ICON_BASE_URL, iconPath);
    }
View Full Code Here

     * Takes a string URI that has the "wlhttp" protocol and creates a URL
     * with the "http" protocol
     */
    private static URL uriToURL(String uri) throws MalformedURLException {
        if (uri == null || uri.startsWith("wlhttp://") == false) {
            throw new MalformedURLException("Invalid wlhttp URI " + uri);
        }
        String url = uri.substring(2);
        return new URL(url);
    }
View Full Code Here

     * Takes a URL that has the "http" protocol and creates a URI with the
     * "wlhttp" protocol
     */
    private static String urlToURI(URL url) throws MalformedURLException {
        if (url == null || url.getProtocol().equals("http") == false) {
            throw new MalformedURLException("Invalid http URL " + url.toExternalForm());
        }
        String uri = "wl" + url.toExternalForm();
        return uri;
    }
View Full Code Here

     *  in the correct form
     */
    public URL getResource(String path) throws MalformedURLException {

  if ((path == null) || (!path.startsWith("/")))
      throw new MalformedURLException
    (sm.getString("standardResources.malformedPath"));
  return (new URL(docRoot + path));

    }
View Full Code Here

                defaultEndpointURL = new URL(this.getTarget().getAddress().getValue());
                defaultEndpointURLString = defaultEndpointURL.toExternalForm();
                return defaultEndpointURL;
            }
            if (endpointInfo.getAddress() == null) {
                throw new MalformedURLException("Invalid address. Endpoint address cannot be null.");
            }
            defaultEndpointURL = new URL(endpointInfo.getAddress());
            defaultEndpointURLString = defaultEndpointURL.toExternalForm();
        }
        return defaultEndpointURL;
View Full Code Here

                defaultEndpointURL = new URL(this.getTarget().getAddress().getValue());
                defaultEndpointURLString = defaultEndpointURL.toExternalForm();
                return defaultEndpointURL;
            }
            if (endpointInfo.getAddress() == null) {
                throw new MalformedURLException("Invalid address. Endpoint address cannot be null.");
            }
            defaultEndpointURL = new URL(endpointInfo.getAddress());
            defaultEndpointURLString = defaultEndpointURL.toExternalForm();
        }
        return defaultEndpointURL;
View Full Code Here

TOP

Related Classes of java.net.MalformedURLException

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.