Package freenet.crypt

Examples of freenet.crypt.DSAGroup


    // 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
View Full Code Here


  }

  public static InsertableClientSSK createRandom(RandomSource r, String docName) {
    byte[] ckey = new byte[CRYPTO_KEY_LENGTH];
    r.nextBytes(ckey);
    DSAGroup g = Global.DSAgroupBigA;
    DSAPrivateKey privKey = new DSAPrivateKey(g, r);
    DSAPublicKey pubKey = new DSAPublicKey(g, privKey);
    try {
      byte[] pkHash = SHA256.digest(pubKey.asBytes());
      return new InsertableClientSSK(docName, pkHash, pubKey, privKey, ckey,
View Full Code Here

 
  public void testSimple() throws IOException {
    final int keys = 10;
    PubkeyStore pk = new PubkeyStore();
    new RAMFreenetStore<DSAPublicKey>(pk, keys);
    DSAGroup group = Global.DSAgroupBigA;
    Random random = new MersenneTwister(1010101);
    HashMap<ByteArrayWrapper, DSAPublicKey> map = new HashMap<ByteArrayWrapper, DSAPublicKey>();
    for(int i=0;i<keys;i++) {
      DSAPrivateKey privKey = new DSAPrivateKey(group, random);
      DSAPublicKey key = new DSAPublicKey(group, privKey);
View Full Code Here

  public void testSimple() {
    final int keys = 10;
    PubkeyStore pk = new PubkeyStore();
    new RAMFreenetStore<DSAPublicKey>(pk, keys);
    GetPubkey pubkeys = new SimpleGetPubkey(pk);
    DSAGroup group = Global.DSAgroupBigA;
    Random random = new MersenneTwister(1010101);
    HashMap<ByteArrayWrapper, DSAPublicKey> map = new HashMap<ByteArrayWrapper, DSAPublicKey>();
    for(int i=0;i<keys;i++) {
      DSAPrivateKey privKey = new DSAPrivateKey(group, random);
      DSAPublicKey key = new DSAPublicKey(group, privKey);
View Full Code Here

    RandomSource random = new DummyRandomSource(12345);
   
    final int CRYPTO_KEY_LENGTH = 32;
    byte[] ckey = new byte[CRYPTO_KEY_LENGTH];
    random.nextBytes(ckey);
    DSAGroup g = Global.DSAgroupBigA;
    DSAPrivateKey privKey = new DSAPrivateKey(g, random);
    DSAPublicKey pubKey = new DSAPublicKey(g, privKey);
    byte[] pkHash = SHA256.digest(pubKey.asBytes());
    String docName = "myDOC";
    InsertableClientSSK ik = new InsertableClientSSK(docName, pkHash, pubKey, privKey, ckey, Key.ALGO_AES_PCFB_256_SHA256);
View Full Code Here

    RandomSource random = new DummyRandomSource(12345);
   
    final int CRYPTO_KEY_LENGTH = 32;
    byte[] ckey = new byte[CRYPTO_KEY_LENGTH];
    random.nextBytes(ckey);
    DSAGroup g = Global.DSAgroupBigA;
    DSAPrivateKey privKey = new DSAPrivateKey(g, random);
    DSAPublicKey pubKey = new DSAPublicKey(g, privKey);
    byte[] pkHash = SHA256.digest(pubKey.asBytes());
    String docName = "myDOC";
    InsertableClientSSK ik = new InsertableClientSSK(docName, pkHash, pubKey, privKey, ckey, Key.ALGO_AES_PCFB_256_SHA256);
View Full Code Here

  static SimpleFieldSet compressedNoderefToFieldSet(byte[] data, int offset, int length) throws FSParseException {
    if(length <= 5)
      throw new FSParseException("Too short");
    // Lookup table for groups.
    DSAGroup group = null;
    int firstByte = data[offset];
    offset++;
    length--;
    if((firstByte & 0x2) == 2) {
      int groupIndex = (data[offset] & 0xff);
      offset++;
      length--;
      group = Global.getGroup(groupIndex);
      if(group == null) throw new FSParseException("Unknown group number "+groupIndex);
      if(logMINOR)
        Logger.minor(PeerNode.class, "DSAGroup set to "+group.fingerprintToString()+ " using the group-index "+groupIndex);
    }
    // Is it compressed?
    if((firstByte & 1) == 1) {
      try {
        // Gzipped
        Inflater i = new Inflater();
        i.setInput(data, offset, length);
        // We shouldn't ever need a 4096 bytes long ref!
        byte[] output = new byte[4096];
        length = i.inflate(output, 0, output.length);
        // Finished
        data = output;
        offset = 0;
        if(logMINOR)
          Logger.minor(PeerNode.class, "We have decompressed a "+length+" bytes big reference.");
      } catch(DataFormatException e) {
        throw new FSParseException("Invalid compressed data");
      }
    }
    if(logMINOR)
      Logger.minor(PeerNode.class, "Reference: " + HexUtil.bytesToHex(data, offset, length) + '(' + length + ')');

    // Now decode it
    ByteArrayInputStream bais = new ByteArrayInputStream(data, offset, length);
    InputStreamReader isr;
    try {
      isr = new InputStreamReader(bais, "UTF-8");
    } catch(UnsupportedEncodingException e1) {
      throw new Error("Impossible: JVM doesn't support UTF-8: " + e1, e1);
    }
    BufferedReader br = new BufferedReader(isr);
    try {
      SimpleFieldSet fs = new SimpleFieldSet(br, false, true);
      if(group != null) {
        SimpleFieldSet sfs = new SimpleFieldSet(true);
        sfs.put("dsaGroup", group.asFieldSet());
        fs.putAllOverwrite(sfs);
      }
      return fs;
    } catch(IOException e) {
      throw (FSParseException)new FSParseException("Impossible: " + e).initCause(e);
View Full Code Here

      }
    }
   
    SimpleFieldSet sfs = fs.subset("dsaGroup");
    if(sfs != null) {
      DSAGroup cmp;
      try {
        cmp = DSAGroup.create(sfs);
      } catch (IllegalBase64Exception e) {
        throw new FSParseException(e);
      }
      if(!cmp.equals(this.peerCryptoGroup))
        throw new FSParseException("Changed DSA group?!");
    }

    sfs = fs.subset("dsaPubKey");
    if(sfs != null) {
View Full Code Here

TOP

Related Classes of freenet.crypt.DSAGroup

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.