1 module hunt.net.secure.conscrypt.SessionSnapshot; 2 3 // dfmt off 4 version(WITH_HUNT_SECURITY): 5 // dfmt on 6 7 import hunt.net.secure.conscrypt.ConscryptSession; 8 import hunt.net.secure.conscrypt.NativeConstants; 9 10 import hunt.net.ssl.SSLSession; 11 import hunt.net.ssl.SSLSessionContext; 12 13 // import hunt.security.cert.Certificate; 14 // import hunt.security.cert.X509Certificate; 15 // import hunt.security.Principal; 16 17 import hunt.collection; 18 19 import hunt.net.Exceptions; 20 import hunt.Exceptions; 21 22 /** 23 * A snapshot of the content of another {@link ConscryptSession}. This copies everything over 24 * except for the certificates. 25 */ 26 final class SessionSnapshot : ConscryptSession { 27 private SSLSessionContext sessionContext; 28 private byte[] id; 29 private string requestedServerName; 30 private List!(byte[]) statusResponses; 31 private byte[] peerTlsSctData; 32 private long creationTime; 33 private long lastAccessedTime; 34 private string cipherSuite; 35 private string protocol; 36 private string peerHost; 37 private int peerPort; 38 39 this(ConscryptSession session) { 40 sessionContext = session.getSessionContext(); 41 id = session.getId(); 42 requestedServerName = session.getRequestedServerName(); 43 statusResponses = session.getStatusResponses(); 44 peerTlsSctData = session.getPeerSignedCertificateTimestamp(); 45 creationTime = session.getCreationTime(); 46 lastAccessedTime = session.getLastAccessedTime(); 47 cipherSuite = session.getCipherSuite(); 48 protocol = session.getProtocol(); 49 peerHost = session.getPeerHost(); 50 peerPort = session.getPeerPort(); 51 } 52 53 override 54 string getRequestedServerName() { 55 return requestedServerName; 56 } 57 58 override 59 List!(byte[]) getStatusResponses() { 60 List!(byte[]) ret = new ArrayList!(byte[])(statusResponses.size()); 61 foreach (byte[] resp ; statusResponses) { 62 ret.add(resp.dup); 63 } 64 return ret; 65 } 66 67 override 68 byte[] getPeerSignedCertificateTimestamp() { 69 return peerTlsSctData !is null ? peerTlsSctData.dup : null; 70 } 71 72 override 73 byte[] getId() { 74 return id; 75 } 76 77 override 78 SSLSessionContext getSessionContext() { 79 return sessionContext; 80 } 81 82 override 83 long getCreationTime() { 84 return creationTime; 85 } 86 87 override 88 long getLastAccessedTime() { 89 return lastAccessedTime; 90 } 91 92 override 93 void invalidate() { 94 // Do nothing. 95 } 96 97 override 98 bool isValid() { 99 return false; 100 } 101 102 override 103 void putValue(string s, Object o) { 104 throw new UnsupportedOperationException( 105 "All calls to this method should be intercepted by ProvidedSessionDecorator."); 106 } 107 108 override 109 Object getValue(string s) { 110 throw new UnsupportedOperationException( 111 "All calls to this method should be intercepted by ProvidedSessionDecorator."); 112 } 113 114 override 115 void removeValue(string s) { 116 throw new UnsupportedOperationException( 117 "All calls to this method should be intercepted by ProvidedSessionDecorator."); 118 } 119 120 override 121 string[] getValueNames() { 122 throw new UnsupportedOperationException( 123 "All calls to this method should be intercepted by ProvidedSessionDecorator."); 124 } 125 126 // override 127 // Certificate[] getPeerCertificates() { 128 // throw new SSLPeerUnverifiedException("No peer certificates"); 129 // } 130 131 // override 132 // Certificate[] getLocalCertificates() { 133 // return null; 134 // } 135 136 // override 137 // X509Certificate[] getPeerCertificateChain(){ 138 // throw new SSLPeerUnverifiedException("No peer certificates"); 139 // } 140 141 // override 142 // Principal getPeerPrincipal() { 143 // throw new SSLPeerUnverifiedException("No peer certificates"); 144 // } 145 146 // override 147 // Principal getLocalPrincipal() { 148 // return null; 149 // } 150 151 override 152 string getCipherSuite() { 153 return cipherSuite; 154 } 155 156 override 157 string getProtocol() { 158 return protocol; 159 } 160 161 override 162 string getPeerHost() { 163 return peerHost; 164 } 165 166 override 167 int getPeerPort() { 168 return peerPort; 169 } 170 171 override 172 int getPacketBufferSize() { 173 return NativeConstants.SSL3_RT_MAX_PACKET_SIZE; 174 } 175 176 override 177 int getApplicationBufferSize() { 178 return NativeConstants.SSL3_RT_MAX_PLAIN_LENGTH; 179 } 180 }