Example usage for org.bouncycastle.util Arrays areEqual

List of usage examples for org.bouncycastle.util Arrays areEqual

Introduction

In this page you can find the example usage for org.bouncycastle.util Arrays areEqual.

Prototype

public static boolean areEqual(short[] a, short[] b) 

Source Link

Usage

From source file:com.bitsofproof.supernode.api.Address.java

License:Apache License

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }/*from   w  w w .  j a v a  2  s. co  m*/
    if (obj == null || getClass() != obj.getClass()) {
        return false;
    }
    return Arrays.areEqual(bytes, ((Address) obj).bytes) && type == ((Address) obj).type;
}

From source file:com.bitsofproof.supernode.api.ExtendedKey.java

License:Apache License

public static ExtendedKey parse(String serialized) throws ValidationException {
    byte[] data = ByteUtils.fromBase58WithChecksum(serialized);
    if (data.length != 78) {
        throw new ValidationException("invalid extended key");
    }/*from   ww  w  .j  a va2  s. c om*/
    byte[] type = Arrays.copyOf(data, 4);
    boolean hasPrivate;
    if (Arrays.areEqual(type, xprv) || Arrays.areEqual(type, tprv)) {
        hasPrivate = true;
    } else if (Arrays.areEqual(type, xpub) || Arrays.areEqual(type, tpub)) {
        hasPrivate = false;
    } else {
        throw new ValidationException("invalid magic number for an extended key");
    }

    int depth = data[4] & 0xff;

    int parent = data[5] & 0xff;
    parent <<= 8;
    parent |= data[6] & 0xff;
    parent <<= 8;
    parent |= data[7] & 0xff;
    parent <<= 8;
    parent |= data[8] & 0xff;

    int sequence = data[9] & 0xff;
    sequence <<= 8;
    sequence |= data[10] & 0xff;
    sequence <<= 8;
    sequence |= data[11] & 0xff;
    sequence <<= 8;
    sequence |= data[12] & 0xff;

    byte[] chainCode = Arrays.copyOfRange(data, 13, 13 + 32);
    byte[] pubOrPriv = Arrays.copyOfRange(data, 13 + 32, data.length);
    Key key;
    if (hasPrivate) {
        key = new ECKeyPair(new BigInteger(1, pubOrPriv), true);
    } else {
        key = new ECPublicKey(pubOrPriv, true);
    }
    return new ExtendedKey(key, chainCode, depth, parent, sequence);
}

From source file:com.bitsofproof.supernode.common.ByteVector.java

License:Apache License

@Override
public boolean equals(Object obj) {
    ByteVector other = (ByteVector) obj;
    return Arrays.areEqual(bytes, other.bytes);
}

From source file:com.bitsofproof.supernode.common.ExtendedKey.java

License:Apache License

@Override
public boolean equals(Object obj) {
    if (obj instanceof ExtendedKey) {
        return master.equals(((ExtendedKey) obj).master)
                && Arrays.areEqual(chainCode, ((ExtendedKey) obj).chainCode)
                && depth == ((ExtendedKey) obj).depth && parent == ((ExtendedKey) obj).parent
                && sequence == ((ExtendedKey) obj).sequence;
    }/*from w  w  w .  j av a 2 s  .c om*/
    return false;
}

From source file:com.gitblit.authority.NewClientCertificateDialog.java

License:Apache License

private boolean validateInputs() {
    if (getExpiration().getTime() < System.currentTimeMillis()) {
        // expires before now
        JOptionPane.showMessageDialog(this, Translation.get("gb.invalidExpirationDate"),
                Translation.get("gb.error"), JOptionPane.ERROR_MESSAGE);
        return false;
    }/*from   w  ww .  j a  va 2  s  .c  o  m*/
    if (pw1.getPassword().length == 0 || !Arrays.areEqual(pw1.getPassword(), pw2.getPassword())) {
        // password mismatch
        JOptionPane.showMessageDialog(this, Translation.get("gb.passwordsDoNotMatch"),
                Translation.get("gb.error"), JOptionPane.ERROR_MESSAGE);
        return false;
    }
    if (StringUtils.isEmpty(getPasswordHint())) {
        // must have hint
        JOptionPane.showMessageDialog(this, Translation.get("gb.passwordHintRequired"),
                Translation.get("gb.error"), JOptionPane.ERROR_MESSAGE);
        return false;
    }
    return true;
}

From source file:com.gitblit.tests.IssuesTest.java

License:Apache License

@Test
public void testLifecycle() throws Exception {
    Repository repository = GitBlitSuite.getIssuesTestRepository();
    String name = FileUtils.getRelativePath(GitBlitSuite.REPOSITORIES, repository.getDirectory());

    // create and insert an issue
    Change c1 = newChange("testCreation() " + Long.toHexString(System.currentTimeMillis()));
    IssueModel issue = IssueUtils.createIssue(repository, c1);
    assertNotNull(issue.id);/*from w  w  w  .  j av  a 2s .co m*/

    // retrieve issue and compare
    IssueModel constructed = IssueUtils.getIssue(repository, issue.id);
    compare(issue, constructed);

    assertEquals(1, constructed.changes.size());

    // C1: create the issue
    c1 = newChange("testUpdates() " + Long.toHexString(System.currentTimeMillis()));
    issue = IssueUtils.createIssue(repository, c1);
    assertNotNull(issue.id);

    constructed = IssueUtils.getIssue(repository, issue.id);
    compare(issue, constructed);
    assertEquals(1, constructed.changes.size());

    // C2: set owner
    Change c2 = new Change("C2");
    c2.comment("I'll fix this");
    c2.setField(Field.Owner, c2.author);
    assertTrue(IssueUtils.updateIssue(repository, issue.id, c2));
    constructed = IssueUtils.getIssue(repository, issue.id);
    assertEquals(2, constructed.changes.size());
    assertEquals(c2.author, constructed.owner);

    // C3: add a note
    Change c3 = new Change("C3");
    c3.comment("yeah, this is working");
    assertTrue(IssueUtils.updateIssue(repository, issue.id, c3));
    constructed = IssueUtils.getIssue(repository, issue.id);
    assertEquals(3, constructed.changes.size());

    // C4: add attachment
    Change c4 = new Change("C4");
    Attachment a = newAttachment();
    c4.addAttachment(a);
    assertTrue(IssueUtils.updateIssue(repository, issue.id, c4));

    Attachment a1 = IssueUtils.getIssueAttachment(repository, issue.id, a.name);
    assertEquals(a.content.length, a1.content.length);
    assertTrue(Arrays.areEqual(a.content, a1.content));

    // C5: close the issue
    Change c5 = new Change("C5");
    c5.comment("closing issue");
    c5.setField(Field.Status, Status.Fixed);
    assertTrue(IssueUtils.updateIssue(repository, issue.id, c5));

    // retrieve issue again
    constructed = IssueUtils.getIssue(repository, issue.id);

    assertEquals(5, constructed.changes.size());
    assertTrue(constructed.status.isClosed());

    List<IssueModel> allIssues = IssueUtils.getIssues(repository, null);
    List<IssueModel> openIssues = IssueUtils.getIssues(repository, new IssueFilter() {
        @Override
        public boolean accept(IssueModel issue) {
            return !issue.status.isClosed();
        }
    });
    List<IssueModel> closedIssues = IssueUtils.getIssues(repository, new IssueFilter() {
        @Override
        public boolean accept(IssueModel issue) {
            return issue.status.isClosed();
        }
    });

    assertTrue(allIssues.size() > 0);
    assertEquals(1, openIssues.size());
    assertEquals(1, closedIssues.size());

    // build a new Lucene index
    LuceneExecutor lucene = new LuceneExecutor(null, GitBlitSuite.REPOSITORIES);
    lucene.deleteIndex(name);
    for (IssueModel anIssue : allIssues) {
        lucene.index(name, anIssue);
    }
    List<SearchResult> hits = lucene.search("working", 1, 10, name);
    assertTrue(hits.size() == 1);

    // reindex an issue
    issue = allIssues.get(0);
    Change change = new Change("reindex");
    change.comment("this is a test of reindexing an issue");
    IssueUtils.updateIssue(repository, issue.id, change);
    issue = IssueUtils.getIssue(repository, issue.id);
    lucene.index(name, issue);

    hits = lucene.search("working", 1, 10, name);
    assertTrue(hits.size() == 1);

    // delete all issues
    for (IssueModel anIssue : allIssues) {
        assertTrue(IssueUtils.deleteIssue(repository, anIssue.id, "D"));
    }

    lucene.close();
    repository.close();
}

From source file:com.gitblit.tests.TicketServiceTest.java

License:Apache License

@Test
public void testLifecycle() throws Exception {
    // query non-existent ticket
    TicketModel nonExistent = service.getTicket(getRepository(), 0);
    assertNull(nonExistent);// w  w  w .  jav a2  s.c o m

    // create and insert a ticket
    Change c1 = newChange("testCreation() " + Long.toHexString(System.currentTimeMillis()));
    TicketModel ticket = service.createTicket(getRepository(), c1);
    assertTrue(ticket.number > 0);

    // retrieve ticket and compare
    TicketModel constructed = service.getTicket(getRepository(), ticket.number);
    compare(ticket, constructed);

    assertEquals(1, constructed.changes.size());

    // C1: create the ticket
    int changeCount = 0;
    c1 = newChange("testUpdates() " + Long.toHexString(System.currentTimeMillis()));
    ticket = service.createTicket(getRepository(), c1);
    assertTrue(ticket.number > 0);
    changeCount++;

    constructed = service.getTicket(getRepository(), ticket.number);
    compare(ticket, constructed);
    assertEquals(1, constructed.changes.size());

    // C2: set owner
    Change c2 = new Change("C2");
    c2.comment("I'll fix this");
    c2.setField(Field.responsible, c2.author);
    constructed = service.updateTicket(getRepository(), ticket.number, c2);
    assertNotNull(constructed);
    assertEquals(2, constructed.changes.size());
    assertEquals(c2.author, constructed.responsible);
    changeCount++;

    // C3: add a note
    Change c3 = new Change("C3");
    c3.comment("yeah, this is working");
    constructed = service.updateTicket(getRepository(), ticket.number, c3);
    assertNotNull(constructed);
    assertEquals(3, constructed.changes.size());
    changeCount++;

    if (service.supportsAttachments()) {
        // C4: add attachment
        Change c4 = new Change("C4");
        Attachment a = newAttachment();
        c4.addAttachment(a);
        constructed = service.updateTicket(getRepository(), ticket.number, c4);
        assertNotNull(constructed);
        assertTrue(constructed.hasAttachments());
        Attachment a1 = service.getAttachment(getRepository(), ticket.number, a.name);
        assertEquals(a.content.length, a1.content.length);
        assertTrue(Arrays.areEqual(a.content, a1.content));
        changeCount++;
    }

    // C5: close the issue
    Change c5 = new Change("C5");
    c5.comment("closing issue");
    c5.setField(Field.status, Status.Resolved);
    constructed = service.updateTicket(getRepository(), ticket.number, c5);
    assertNotNull(constructed);
    changeCount++;
    assertTrue(constructed.isClosed());
    assertEquals(changeCount, constructed.changes.size());

    List<TicketModel> allTickets = service.getTickets(getRepository());
    List<TicketModel> openTickets = service.getTickets(getRepository(), new TicketFilter() {
        @Override
        public boolean accept(TicketModel ticket) {
            return ticket.isOpen();
        }
    });
    List<TicketModel> closedTickets = service.getTickets(getRepository(), new TicketFilter() {
        @Override
        public boolean accept(TicketModel ticket) {
            return ticket.isClosed();
        }
    });
    assertTrue(allTickets.size() > 0);
    assertEquals(1, openTickets.size());
    assertEquals(1, closedTickets.size());

    // build a new Lucene index
    service.reindex(getRepository());
    List<QueryResult> hits = service.searchFor(getRepository(), "working", 1, 10);
    assertEquals(1, hits.size());

    // reindex a ticket
    ticket = allTickets.get(0);
    Change change = new Change("reindex");
    change.comment("this is a test of reindexing a ticket");
    service.updateTicket(getRepository(), ticket.number, change);
    ticket = service.getTicket(getRepository(), ticket.number);

    hits = service.searchFor(getRepository(), "reindexing", 1, 10);
    assertEquals(1, hits.size());

    service.stop();
    service = getService(false);

    // Lucene field query
    List<QueryResult> results = service.queryFor(Lucene.status.matches(Status.New.name()), 1, 10,
            Lucene.created.name(), true);
    assertEquals(1, results.size());
    assertTrue(results.get(0).title.startsWith("testCreation"));

    // Lucene field query
    results = service.queryFor(Lucene.status.matches(Status.Resolved.name()), 1, 10, Lucene.created.name(),
            true);
    assertEquals(1, results.size());
    assertTrue(results.get(0).title.startsWith("testUpdates"));

    // check the ids
    assertEquals("[1, 2]", service.getIds(getRepository()).toString());

    // delete all tickets
    for (TicketModel aTicket : allTickets) {
        assertTrue(service.deleteTicket(getRepository(), aTicket.number, "D"));
    }
}

From source file:com.github.horrorho.inflatabledonkey.crypto.key.Keys.java

License:Open Source License

static void checkPublicExportData(byte[] publicExportData, Optional<PublicKeyInfo> publicKeyInfo) {
    if (publicKeyInfo.isPresent()) {
        byte[] publicInfoExportedKeyData = publicKeyInfo.get().key();

        if (Arrays.areEqual(publicExportData, publicInfoExportedKeyData)) {
            logger.debug("-- checkPublicExportData() - public export data match: {}",
                    Hex.toHexString(publicExportData));
        } else {//w ww .ja  v a 2 s  .  c  o  m
            logger.warn(
                    "-- checkPublicExportData() - public export data mismatch, supplied: {}, public key info: {}",
                    Hex.toHexString(publicExportData), Hex.toHexString(publicInfoExportedKeyData));
        }
    }
}

From source file:com.github.horrorho.inflatabledonkey.file.FileStreamWriter.java

License:Open Source License

static boolean testSignature(Digest digest, byte[] signature) {
    byte[] out = signature(digest);
    boolean match = Arrays.areEqual(out, signature);
    if (match) {/*ww w.  j  a va2s. c o m*/
        logger.debug("-- testSignature() - positive match out: 0x{} target: 0x{}", Hex.toHexString(out),
                Hex.toHexString(signature));
    } else {

        logger.warn("-- testSignature() - negative match out: 0x{} target: 0x{}", Hex.toHexString(out),
                Hex.toHexString(signature));
    }
    return match;
}

From source file:com.github.horrorho.inflatabledonkey.pcs.xfile.FileKeyAssistant.java

License:Open Source License

public static Optional<byte[]> unwrap(KeyBag keyBag, int protectionClass, byte[] fileKey) {
    Optional<byte[]> optionalPublicKey = keyBag.publicKey(protectionClass);
    Optional<byte[]> optionalPrivateKey = keyBag.privateKey(protectionClass);
    Optional<byte[]> uuid = uuid(fileKey);

    boolean uuidMatch = uuid.map(u -> Arrays.areEqual(keyBag.uuid(), u)).orElse(false);
    if (!uuidMatch) {
        logger.warn("-- unwrap() - fileKey/ keybag uuid mismatch: 0x{} 0x{}", uuid.map(Hex::toHexString),
                Hex.toHexString(keyBag.uuid()));
    }//from w  w  w. jav  a 2 s.c o m

    return optionalPublicKey.isPresent() && optionalPrivateKey.isPresent()
            ? unwrap(optionalPublicKey.get(), optionalPrivateKey.get(), protectionClass, fileKey)
            : Optional.empty();
}