1 module hunt.net.secure.conscrypt.SSLNullSession; 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.SSLSessionContext; 11 12 // import hunt.security.cert.Certificate; 13 // import hunt.security.cert.X509Certificate; 14 // import hunt.security.Principal; 15 16 import hunt.net.Exceptions; 17 18 import hunt.collection; 19 20 import hunt.util.DateTime; 21 import hunt.Exceptions; 22 23 24 /** 25 * This is returned in the place of a {@link SSLSession} when no TLS connection could be negotiated, 26 * but one was requested from a method that can't throw an exception such as {@link 27 * javax.net.ssl.SSLSocket#getSession()} before {@link javax.net.ssl.SSLSocket#startHandshake()} is 28 * called. 29 */ 30 final class SSLNullSession : ConscryptSession { // 31 enum string INVALID_CIPHER = "SSL_NULL_WITH_NULL_NULL"; 32 33 /* 34 * Holds default instances so class preloading doesn't create an instance of 35 * it. 36 */ 37 private static class DefaultHolder { 38 __gshared SSLNullSession NULL_SESSION; // = new SSLNullSession(); 39 40 shared static this() 41 { 42 NULL_SESSION = new SSLNullSession(); 43 } 44 45 } 46 47 private long creationTime; 48 private long lastAccessedTime; 49 50 static ConscryptSession getNullSession() { 51 return DefaultHolder.NULL_SESSION; 52 } 53 54 // static bool isNullSession(SSLSession session) { 55 // return SSLUtils.unwrapSession(session) == DefaultHolder.NULL_SESSION; 56 // } 57 58 // private SSLNullSession() { 59 // creationTime = DateTimeHelper.currentTimeMillis(); 60 // lastAccessedTime = creationTime; 61 // } 62 63 override 64 string getRequestedServerName() { 65 return null; 66 } 67 68 override 69 List!(byte[]) getStatusResponses() { 70 return new EmptyList!(byte[])(); 71 } 72 73 override 74 byte[] getPeerSignedCertificateTimestamp() { 75 return []; 76 } 77 78 override 79 int getApplicationBufferSize() { 80 return NativeConstants.SSL3_RT_MAX_PLAIN_LENGTH; 81 } 82 83 override 84 string getCipherSuite() { 85 return INVALID_CIPHER; 86 } 87 88 override 89 long getCreationTime() { 90 return creationTime; 91 } 92 93 override 94 byte[] getId() { 95 return []; 96 } 97 98 override 99 long getLastAccessedTime() { 100 return lastAccessedTime; 101 } 102 103 // override 104 // Certificate[] getLocalCertificates() { 105 // return null; 106 // } 107 108 // override 109 // Principal getLocalPrincipal() { 110 // return null; 111 // } 112 113 override 114 int getPacketBufferSize() { 115 return NativeConstants.SSL3_RT_MAX_PACKET_SIZE; 116 } 117 118 // override 119 // X509Certificate[] getPeerCertificateChain(){ 120 // throw new SSLPeerUnverifiedException("No peer certificate"); 121 // } 122 123 // override 124 // Certificate[] getPeerCertificates(){ 125 // throw new SSLPeerUnverifiedException("No peer certificate"); 126 // } 127 128 override 129 string getPeerHost() { 130 return null; 131 } 132 133 override 134 int getPeerPort() { 135 return -1; 136 } 137 138 // override 139 // Principal getPeerPrincipal(){ 140 // throw new SSLPeerUnverifiedException("No peer certificate"); 141 // } 142 143 override 144 string getProtocol() { 145 return "NONE"; 146 } 147 148 override 149 SSLSessionContext getSessionContext() { 150 return null; 151 } 152 153 override 154 Object getValue(string name) { 155 throw new UnsupportedOperationException( 156 "All calls to this method should be intercepted by ProvidedSessionDecorator."); 157 } 158 159 override 160 string[] getValueNames() { 161 throw new UnsupportedOperationException( 162 "All calls to this method should be intercepted by ProvidedSessionDecorator."); 163 } 164 165 override 166 void invalidate() { 167 } 168 169 override 170 bool isValid() { 171 return false; 172 } 173 174 override 175 void putValue(string name, Object value) { 176 throw new UnsupportedOperationException( 177 "All calls to this method should be intercepted by ProvidedSessionDecorator."); 178 } 179 180 override 181 void removeValue(string name) { 182 throw new UnsupportedOperationException( 183 "All calls to this method should be intercepted by ProvidedSessionDecorator."); 184 } 185 }