@@ -588,6 +588,9 @@ void Connection::Initialize(Handle<Object> target) {
588588 NODE_SET_PROTOTYPE_METHOD (t, " clearPending" , Connection::ClearPending);
589589 NODE_SET_PROTOTYPE_METHOD (t, " encPending" , Connection::EncPending);
590590 NODE_SET_PROTOTYPE_METHOD (t, " getPeerCertificate" , Connection::GetPeerCertificate);
591+ NODE_SET_PROTOTYPE_METHOD (t, " getSession" , Connection::GetSession);
592+ NODE_SET_PROTOTYPE_METHOD (t, " setSession" , Connection::SetSession);
593+ NODE_SET_PROTOTYPE_METHOD (t, " isSessionReused" , Connection::IsSessionReused);
591594 NODE_SET_PROTOTYPE_METHOD (t, " isInitFinished" , Connection::IsInitFinished);
592595 NODE_SET_PROTOTYPE_METHOD (t, " verifyError" , Connection::VerifyError);
593596 NODE_SET_PROTOTYPE_METHOD (t, " getCurrentCipher" , Connection::GetCurrentCipher);
@@ -1175,6 +1178,91 @@ Handle<Value> Connection::GetPeerCertificate(const Arguments& args) {
11751178 return scope.Close (info);
11761179}
11771180
1181+ Handle<Value> Connection::GetSession (const Arguments& args) {
1182+ HandleScope scope;
1183+
1184+ Connection *ss = Connection::Unwrap (args);
1185+
1186+ if (ss->ssl_ == NULL ) return Undefined ();
1187+
1188+ SSL_SESSION * sess = SSL_get_session (ss->ssl_ );
1189+ if (!sess) return Undefined ();
1190+
1191+ int slen = i2d_SSL_SESSION (sess, NULL );
1192+ assert (slen > 0 );
1193+
1194+ Local<Value> s;
1195+
1196+ if (slen > 0 ) {
1197+ void * pp = malloc (slen);
1198+ if (pp)
1199+ {
1200+ unsigned char * p = (unsigned char *)pp;
1201+ i2d_SSL_SESSION (sess, &p);
1202+ s = Encode (pp, slen, BINARY );
1203+ free (pp);
1204+ }
1205+ else
1206+ return False ();
1207+ }
1208+ else
1209+ return False ();
1210+
1211+ return scope.Close (s);
1212+ }
1213+
1214+ Handle<Value> Connection::SetSession (const Arguments& args) {
1215+ HandleScope scope;
1216+
1217+ Connection *ss = Connection::Unwrap (args);
1218+
1219+ if (args.Length () < 1 || !args[0 ]->IsString ()) {
1220+ Local<Value> exception = Exception::TypeError (String::New (" Bad argument" ));
1221+ return ThrowException (exception);
1222+ }
1223+
1224+ ASSERT_IS_STRING_OR_BUFFER (args[0 ]);
1225+ ssize_t slen = DecodeBytes (args[0 ], BINARY );
1226+
1227+ if (slen < 0 ) {
1228+ Local<Value> exception = Exception::TypeError (String::New (" Bad argument" ));
1229+ return ThrowException (exception);
1230+ }
1231+
1232+ char * sbuf = new char [slen];
1233+
1234+ ssize_t wlen = DecodeWrite (sbuf, slen, args[0 ], BINARY );
1235+ assert (wlen == slen);
1236+
1237+ const unsigned char * p = (unsigned char *) sbuf;
1238+ SSL_SESSION * sess = d2i_SSL_SESSION (NULL , &p, wlen);
1239+
1240+ delete [] sbuf;
1241+
1242+ if (!sess)
1243+ return Undefined ();
1244+
1245+ int r = SSL_set_session (ss->ssl_ , sess);
1246+ SSL_SESSION_free (sess);
1247+
1248+ if (!r) {
1249+ Local<String> eStr = String::New (" SSL_set_session error" );
1250+ return ThrowException (Exception::Error (eStr));
1251+ }
1252+
1253+ return True ();
1254+ }
1255+
1256+ Handle<Value> Connection::IsSessionReused (const Arguments& args) {
1257+ HandleScope scope;
1258+
1259+ Connection *ss = Connection::Unwrap (args);
1260+
1261+ if (ss->ssl_ == NULL ) return False ();
1262+ return SSL_session_reused (ss->ssl_ ) ? True () : False ();
1263+ }
1264+
1265+
11781266Handle<Value> Connection::Start (const Arguments& args) {
11791267 HandleScope scope;
11801268
0 commit comments