Blame nss/lib/ssl/notes.txt

Packit 40b132
# This Source Code Form is subject to the terms of the Mozilla Public
Packit 40b132
# License, v. 2.0. If a copy of the MPL was not distributed with this
Packit 40b132
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
Packit 40b132
Packit 40b132
SSL's Buffers: enumerated and explained.
Packit 40b132
Packit 40b132
---------------------------------------------------------------------------
Packit 40b132
incoming:
Packit 40b132
Packit 40b132
gs = ss->gather
Packit 40b132
hs = ss->ssl3->hs
Packit 40b132
Packit 40b132
gs->inbuf	SSL3 only: incoming (encrypted) ssl records are placed here,
Packit 40b132
		and then decrypted (or copied) to gs->buf.
Packit 40b132
Packit 40b132
gs->buf		SSL2: incoming SSL records are put here, and then decrypted
Packit 40b132
		in place.
Packit 40b132
		SSL3: ssl3_HandleHandshake puts decrypted ssl records here.
Packit 40b132
Packit 40b132
hs.msg_body	(SSL3 only) When an incoming handshake message spans more 
Packit 40b132
		than one ssl record, the first part(s) of it are accumulated 
Packit 40b132
		here until it all arrives.
Packit 40b132
Packit 40b132
hs.msgState	(SSL3 only) an alternative set of pointers/lengths for gs->buf.
Packit 40b132
		Used only when a handleHandshake function returns SECWouldBlock.
Packit 40b132
		ssl3_HandleHandshake remembers how far it previously got by
Packit 40b132
		using these pointers instead of gs->buf when it is called 
Packit 40b132
		after a previous SECWouldBlock return.
Packit 40b132
Packit 40b132
---------------------------------------------------------------------------
Packit 40b132
outgoing:
Packit 40b132
Packit 40b132
sec = ss->sec
Packit 40b132
ci  = ss->sec->ci	/* connect info */
Packit 40b132
Packit 40b132
ci->sendBuf	Outgoing handshake messages are appended to this buffer.
Packit 40b132
		This buffer will then be sent as a single SSL record.
Packit 40b132
Packit 40b132
sec->writeBuf	outgoing ssl records are constructed here and encrypted in 
Packit 40b132
		place before being written or copied to pendingBuf.
Packit 40b132
Packit 40b132
ss->pendingBuf	contains outgoing ciphertext that was saved after a write
Packit 40b132
		attempt to the socket failed, e.g. EWouldBlock. 
Packit 40b132
		Generally empty with blocking sockets (should be no incomplete
Packit 40b132
		writes).
Packit 40b132
Packit 40b132
ss->saveBuf	Used only by socks code.  Intended to be used to buffer 
Packit 40b132
		outgoing data until a socks handshake completes.  However,
Packit 40b132
		this buffer is always empty.  There is no code to put 
Packit 40b132
		anything into it.
Packit 40b132
Packit 40b132
---------------------------------------------------------------------------
Packit 40b132
Packit 40b132
SECWouldBlock means that the function cannot make progress because it is 
Packit 40b132
waiting for some event OTHER THAN socket I/O completion (e.g. waiting for 
Packit 40b132
user dialog to finish).  It is not the same as EWOULDBLOCK.
Packit 40b132
Packit 40b132
---------------------------------------------------------------------------
Packit 40b132
Packit 40b132
Rank (order) of locks
Packit 40b132
Packit 40b132
recvLock ->\ firstHandshake -> recvbuf -> ssl3Handshake -> xmitbuf -> "spec"
Packit 40b132
sendLock ->/
Packit 40b132
Packit 40b132
crypto and hash Data that must be protected while turning plaintext into
Packit 40b132
ciphertext:
Packit 40b132
Packit 40b132
SSL2: 	(in ssl2_Send*)
Packit 40b132
	sec->hash*
Packit 40b132
	sec->hashcx 	(ptr and data)
Packit 40b132
	sec->enc
Packit 40b132
	sec->writecx*	(ptr and content)
Packit 40b132
	sec->sendSecret*(ptr and content)
Packit 40b132
	sec->sendSequence		locked by xmitBufLock
Packit 40b132
	sec->blockSize
Packit 40b132
	sec->writeBuf*  (ptr & content)	locked by xmitBufLock
Packit 40b132
	"in"				locked by xmitBufLock
Packit 40b132
Packit 40b132
SSl3:	(in ssl3_SendPlainText)
Packit 40b132
	ss->ssl3		    (the pointer)
Packit 40b132
	ss->ssl3->current_write*    (the pointer and the data in the spec
Packit 40b132
				     and any data referenced by the spec.
Packit 40b132
Packit 40b132
	ss->sec->isServer
Packit 40b132
	ss->sec->writebuf* (ptr & content) locked by xmitBufLock
Packit 40b132
	"buf" 				   locked by xmitBufLock
Packit 40b132
Packit 40b132
crypto and hash data that must be protected while turning ciphertext into 
Packit 40b132
plaintext:
Packit 40b132
Packit 40b132
SSL2:	(in ssl2_GatherData)
Packit 40b132
	gs->*				(locked by recvBufLock )
Packit 40b132
	sec->dec
Packit 40b132
	sec->readcx
Packit 40b132
	sec->hash* 		(ptr and data)
Packit 40b132
	sec->hashcx 		(ptr and data)
Packit 40b132
Packit 40b132
SSL3:	(in ssl3_HandleRecord )
Packit 40b132
	ssl3->current_read*	(the pointer and all data refernced)
Packit 40b132
	ss->sec->isServer
Packit 40b132
Packit 40b132
Packit 40b132
Data that must be protected while being used by a "writer":
Packit 40b132
Packit 40b132
ss->pendingBuf.*
Packit 40b132
ss->saveBuf.*		(which is dead)
Packit 40b132
Packit 40b132
in ssl3_sendPlainText
Packit 40b132
Packit 40b132
ss->ssl3->current_write-> (spec)
Packit 40b132
ss->sec->writeBuf.*
Packit 40b132
ss->sec->isServer 
Packit 40b132
Packit 40b132
in SendBlock
Packit 40b132
Packit 40b132
ss->sec->hash->length
Packit 40b132
ss->sec->blockSize
Packit 40b132
ss->sec->writeBuf.*
Packit 40b132
ss->sec->sendSecret
Packit 40b132
ss->sec->sendSequence
Packit 40b132
ss->sec->writecx	*
Packit 40b132
ss->pendingBuf
Packit 40b132
Packit 40b132
--------------------------------------------------------------------------
Packit 40b132
Packit 40b132
Data variables (not const) protected by the "sslGlobalDataLock".  
Packit 40b132
Note, this really should be a reader/writer lock.
Packit 40b132
Packit 40b132
allowedByPolicy		sslcon.c
Packit 40b132
maybeAllowedByPolicy	sslcon.c
Packit 40b132
chosenPreference	sslcon.c
Packit 40b132
policyWasSet		sslcon.c
Packit 40b132
Packit 40b132
cipherSuites[] 		ssl3con.c