peerId = PR_smprintf("%s:%d", host, port); if (SECSuccess != SSL_SetSockPeerID(layer, peerId)) { PR_smprintf_free(peerId); goto loser; }  PR_smprintf_free(peerId);
nsSSLIOLayerAddToSocket(const char* host,                        PRInt32 port,                        const char* proxyHost,                        PRInt32 proxyPort,                        PRFileDesc* fd,                        nsISupports** info,                        PRBool forTLSStepUp){  PRFileDesc* layer = nsnull;  nsresult rv;  PRInt32 ret;  if (firstTime) {    rv = InitNSSMethods();    if (NS_FAILED(rv)) return rv;    firstTime = PR_FALSE;  }  nsNSSSocketInfo* infoObject = new nsNSSSocketInfo();  if (!infoObject) return NS_ERROR_FAILURE;    NS_ADDREF(infoObject);    infoObject->SetHostName(host);  infoObject->SetHostPort(port);  infoObject->SetProxyName(proxyHost);  infoObject->SetProxyPort(proxyPort);  infoObject->SetForTLSStepUp(forTLSStepUp);  PRFileDesc* sslSock = SSL_ImportFD(nsnull, fd);  if (!sslSock) {    NS_ASSERTION(PR_FALSE, "NSS: Error importing socket");    goto loser;  }  infoObject->SetFileDescPtr(sslSock);  SSL_SetPKCS11PinArg(sslSock, (nsIInterfaceRequestor*)infoObject);  SSL_HandshakeCallback(sslSock, HandshakeCallback, infoObject);  SSL_GetClientAuthDataHook(sslSock, (SSLGetClientAuthData)nsNSS_SSLGetClientAuthData,                            infoObject);  ret = SSL_SetURL(sslSock, host);  if (ret == -1) {    NS_ASSERTION(PR_FALSE, "NSS: Error setting server name");    goto loser;  }    /* Now, layer ourselves on top of the SSL socket... */  layer = PR_CreateIOLayerStub(nsSSLIOLayerIdentity,                               &nsSSLIOLayerMethods);  if (!layer)    goto loser;    layer->secret = (PRFilePrivate*) infoObject;  rv = PR_PushIOLayer(sslSock, PR_GetLayersIdentity(sslSock), layer);    if (NS_FAILED(rv)) {    goto loser;  }  PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("[%p] Socket set up\n", (void*)sslSock));  infoObject->QueryInterface(NS_GET_IID(nsISupports), (void**) (info));  if ((forTLSStepUp || proxyHost) &&      SECSuccess != SSL_OptionSet(sslSock, SSL_SECURITY, PR_FALSE))    goto loser;  if (forTLSStepUp) {    if (SECSuccess != SSL_OptionSet(sslSock, SSL_ENABLE_SSL2, PR_FALSE)) {      goto loser;    }    if (SECSuccess != SSL_OptionSet(sslSock, SSL_V2_COMPATIBLE_HELLO, PR_FALSE)) {      goto loser;    }  }      if (SECSuccess != SSL_OptionSet(sslSock, SSL_HANDSHAKE_AS_CLIENT, PR_TRUE)) {    goto loser;  }  if (SECSuccess != SSL_OptionSet(sslSock, SSL_ENABLE_FDX, PR_TRUE)) {    goto loser;  }  if (SECSuccess != SSL_BadCertHook(sslSock, (SSLBadCertHandler) nsNSSBadCertHandler,                                    infoObject)) {    goto loser;  }  return NS_OK; loser:  NS_IF_RELEASE(infoObject);  PR_FREEIF(layer);  return NS_ERROR_FAILURE;}