Ejemplo n.º 1
0
 public String getDomain() {
   try {
     return Base32.encode(Base64.decode(identity)).toLowerCase(Locale.ROOT) + ".freemail";
   } catch (IllegalBase64Exception e) {
     // This would mean that WoT has changed the encoding of the identity string
     throw new AssertionError("Got IllegalBase64Exception when decoding " + identity);
   }
 }
Ejemplo n.º 2
0
  FreemailAccount(String identity, File _accdir, PropsFile _accprops, Freemail freemail) {
    if (!FreenetURI.checkSSKHash(identity)) {
      throw new IllegalArgumentException("Expected valid identity string, but got " + identity);
    }
    try {
      Base64.decode(identity);
    } catch (IllegalBase64Exception e) {
      throw new IllegalArgumentException("Couldn't decode identity string: " + identity, e);
    }

    this.identity = identity;
    accdir = _accdir;
    accprops = _accprops;
    mb = new MessageBank(this);

    File channelDir = new File(accdir, "channel");
    messageHandler =
        new MessageHandler(
            new File(accdir, "outbox"),
            freemail,
            channelDir,
            this,
            new HighLevelFCPClientFactory());
  }
Ejemplo n.º 3
0
  public FreenetURI(String URI) throws MalformedURLException {
    //		this.uniqueHashCode = super.hashCode();
    if (URI == null) throw new MalformedURLException("No URI specified");

    URI = URI.trim();
    if (URI.indexOf('@') < 0 || URI.indexOf('/') < 0)
      // Encoded URL?
      try {
        URI = URLDecoder.decode(URI, false);
      } catch (URLEncodedFormatException e) {
        throw new MalformedURLException(
            "Invalid URI: no @ or /, or @ or / is escaped but there are invalid escapes");
      }

    URI = URI_PREFIX.matcher(URI).replaceFirst("");

    // decode keyType
    int atchar = URI.indexOf('@');
    if (atchar == -1) throw new MalformedURLException("There is no @ in that URI! (" + URI + ')');

    String _keyType = URI.substring(0, atchar).toUpperCase();
    URI = URI.substring(atchar + 1);

    boolean validKeyType = false;
    for (int i = 0; i < VALID_KEY_TYPES.length; i++) {
      if (_keyType.equals(VALID_KEY_TYPES[i])) {
        validKeyType = true;
        _keyType = VALID_KEY_TYPES[i];
        break;
      }
    }
    keyType = _keyType;
    if (!validKeyType) throw new MalformedURLException("Invalid key type: " + keyType);

    boolean isSSK = "SSK".equals(keyType);
    boolean isUSK = "USK".equals(keyType);
    boolean isKSK = "KSK".equals(keyType);

    // decode metaString
    ArrayList<String> sv = null;
    int slash2;
    sv = new ArrayList<String>();
    if (isKSK) URI = "/" + URI; // ensure that KSK docNames are decoded
    while ((slash2 = URI.lastIndexOf('/')) != -1) {
      String s;
      try {
        s = URLDecoder.decode(URI.substring(slash2 + 1 /* "/".length() */), true);
      } catch (URLEncodedFormatException e) {
        MalformedURLException ue = new MalformedURLException(e.toString());
        ue.initCause(e);
        throw ue;
      }
      if (s != null) sv.add(s);
      URI = URI.substring(0, slash2);
    }

    // sv is *backwards*
    // this makes for more efficient handling

    if (isSSK || isUSK || isKSK) {

      if (sv.isEmpty()) throw new MalformedURLException("No docname for " + keyType);
      docName = sv.remove(sv.size() - 1);
      if (isUSK) {
        if (sv.isEmpty()) throw new MalformedURLException("No suggested edition number for USK");
        try {
          suggestedEdition = Long.parseLong(sv.remove(sv.size() - 1));
        } catch (NumberFormatException e) {
          MalformedURLException e1 = new MalformedURLException("Invalid suggested edition: " + e);
          e1.initCause(e);
          throw e1;
        }
      } else suggestedEdition = -1;
    } else {
      // docName not necessary, nor is it supported, for CHKs.
      docName = null;
      suggestedEdition = -1;
    }

    if (!sv.isEmpty()) {
      metaStr = new String[sv.size()];
      for (int i = 0; i < metaStr.length; i++) {
        metaStr[i] = sv.get(metaStr.length - 1 - i).intern();
        if (metaStr[i] == null) throw new NullPointerException();
      }
    } else metaStr = null;

    if (isKSK) {
      routingKey = extra = cryptoKey = null;
      return;
    }

    // strip 'file extensions' from CHKs
    // added by aum ([email protected])
    if ("CHK".equals(keyType)) URI = URI.split("[.]")[0];

    // URI now contains: routingKey[,cryptoKey][,metaInfo]
    StringTokenizer st = new StringTokenizer(URI, ",");
    try {
      if (st.hasMoreTokens()) routingKey = Base64.decode(st.nextToken());
      else {
        routingKey = cryptoKey = extra = null;
        return;
      }
      if (!st.hasMoreTokens()) {
        cryptoKey = extra = null;
        return;
      }

      // Can be cryptokey or name-value pair.
      String t = st.nextToken();
      cryptoKey = Base64.decode(t);
      if (!st.hasMoreTokens()) {
        extra = null;
        return;
      }
      extra = Base64.decode(st.nextToken());

    } catch (IllegalBase64Exception e) {
      throw new MalformedURLException("Invalid Base64 quantity: " + e);
    }
    if (logDEBUG)
      Logger.minor(
          this, "Created from parse: " + toString() + " from " + URI, new Exception("debug"));
  }