1132 lines · 40.0 KB · Java
RawDownload
            fetchAttributes(attributes);             try {                params = P11ECKeyFactory.decodeParameters                            (attributes[1].getByteArray());                 /*                 * An uncompressed EC point may be in either of two formats.                 * First try the OCTET STRING encoding:                 *   04 <length> 04 <X-coordinate> <Y-coordinate>                 *                 * Otherwise try the raw encoding:                 *   04 <X-coordinate> <Y-coordinate>                 */                byte[] ecKey = attributes[0].getByteArray();                 try {                    DerValue wECPoint = new DerValue(ecKey);                    if (wECPoint.getTag() != DerValue.tag_OctetString)                        throw new IOException("Unexpected tag: " +                            wECPoint.getTag());                     w = P11ECKeyFactory.decodePoint                        (wECPoint.getDataBytes(), params.getCurve());                 } catch (IOException e) {                    // Failover                    w = P11ECKeyFactory.decodePoint(ecKey, params.getCurve());                }             } catch (Exception e) {                throw new RuntimeException("Could not parse key values", e);            }        }        public String getFormat() {            token.ensureValid();            return "X.509";        }        synchronized byte[] getEncodedInternal() {            token.ensureValid();            if (encoded == null) {                fetchValues();                try {                    Key key = new sun.security.ec.ECPublicKeyImpl(w, params);                    encoded = key.getEncoded();                } catch (InvalidKeyException e) {                    throw new ProviderException(e);                }            }            return encoded;        }        public ECPoint getW() {            fetchValues();            return w;        }        public ECParameterSpec getParams() {            fetchValues();            return params;        }        public String toString() {            fetchValues();            return super.toString()                + "\n  public x coord: " + w.getAffineX()                + "\n  public y coord: " + w.getAffineY()                + "\n  parameters: " + params;        }    }} /* * NOTE: Must use PhantomReference here and not WeakReference * otherwise the key maybe cleared before other objects which * still use these keys during finalization such as SSLSocket. */final class SessionKeyRef extends PhantomReference<P11Key>    implements Comparable<SessionKeyRef> {    private static ReferenceQueue<P11Key> refQueue =        new ReferenceQueue<P11Key>();    private static Set<SessionKeyRef> refList =        Collections.synchronizedSortedSet(new TreeSet<SessionKeyRef>());     static ReferenceQueue<P11Key> referenceQueue() {        return refQueue;    }     private static void drainRefQueueBounded() {        while (true) {            SessionKeyRef next = (SessionKeyRef) refQueue.poll();            if (next == null) break;            next.dispose();        }    }     // handle to the native key    private long keyID;    private Session session;     SessionKeyRef(P11Key key , long keyID, Session session) {        super(key, refQueue);        this.keyID = keyID;        this.session = session;        this.session.addObject();        refList.add(this);        // TBD: run at some interval and not every time?        drainRefQueueBounded();    }     private void dispose() {        refList.remove(this);        if (session.token.isValid()) {            Session newSession = null;            try {                newSession = session.token.getOpSession();                session.token.p11.C_DestroyObject(newSession.id(), keyID);            } catch (PKCS11Exception e) {                // ignore            } finally {                this.clear();                session.token.releaseSession(newSession);                session.removeObject();            }        }    }     public int compareTo(SessionKeyRef other) {        if (this.keyID == other.keyID) {            return 0;        } else {            return (this.keyID < other.keyID) ? -1 : 1;        }    }}

Lines 1001–1132 of 1132. Previous lines

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t