summaryrefslogtreecommitdiffstats
blob: fdd64c05cc989aa9724895467d153d29fe4d9b18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
 * Copyright (c) 2011-2012 Isode Limited, London, England.
 * All rights reserved.
 */
/*
 * Copyright (c) 2010 Remko Tronçon.
 * All rights reserved.
 */
package com.isode.stroke.tls;

import com.isode.stroke.base.ByteArray;
import com.isode.stroke.crypto.CryptoProvider;
import com.isode.stroke.stringcodecs.Hexify;
import com.isode.stroke.stringcodecs.SHA1;
import java.util.List;

public abstract class Certificate {

    /**
     * Returns the textual representation of the full Subject
     * name.
     */
    public abstract String getSubjectName();

    public abstract List<String> getCommonNames();

    public abstract List<String> getSRVNames();

    public abstract List<String> getDNSNames();

    public abstract List<String> getXMPPAddresses();

    public abstract ByteArray toDER();

    public static String getSHA1Fingerprint(Certificate certificate, CryptoProvider crypto) {
        ByteArray hash = crypto.getSHA1Hash(certificate.toDER());
        StringBuilder s = new StringBuilder();
        for (int i = 0; i < hash.getSize(); ++i) {
            if (i > 0) {
                s.append(":");
            }
            s.append(Hexify.hexify(hash.getData()[i]));
        }
        return s.toString();
    }
    protected String ID_ON_XMPPADDR_OID = "1.3.6.1.5.5.7.8.5";
    protected String ID_ON_DNSSRV_OID = "1.3.6.1.5.5.7.8.7";
}