| plan 9 kernel history: overview | file list | diff list |
2000/0913/port/devssl.c (diff list | history)
| 2000/0325/sys/src/9/port/devssl.c:72,78 – 2000/0913/sys/src/9/port/devssl.c:72,78 (short | long | prev | next) | ||
| 1995/1213 | ||
| 1996/1029 | Lock dslock; int dshiwat; | |
| 2000/0913 | int maxdstate = 128; | |
| 1996/1029 | Dstate** dstate; | |
| 1998/0417 | char *encalgs; char *hashalgs; | |
| 2000/0325/sys/src/9/port/devssl.c:431,436 – 2000/0913/sys/src/9/port/devssl.c:431,459 | ||
| 1996/1029 | } /* | |
| 2000/0913 | * give back n bytes */ static void regurgitate(Dstate *s, uchar *p, int n) { Block *b; if(n <= 0) return; b = s->unprocessed; if(s->unprocessed == nil || b->rp - b->base < n) { b = allocb(n); memmove(p, b->wp, n); b->wp += n; b->next = s->unprocessed; s->unprocessed = b; } else { b->rp -= n; memmove(p, b->rp, n); } } /* | |
| 1996/1029 | * remove at most n bytes from the queue, if discard is set * dump the remainder */ | |
| 2000/0325/sys/src/9/port/devssl.c:478,489 – 2000/0913/sys/src/9/port/devssl.c:501,520 | ||
| 1996/1029 | return first; } | |
| 2000/0913 | /* * We can't let Eintr's lose data since the program * doing the read may be able to handle it. The only * places Eintr is possible is during the read's in consume. * Therefore, we make sure we can always put back the bytes * consumed before the last ensure. */ | |
| 1997/0327 | static Block* | |
| 1998/0327 | sslbread(Chan *c, long n, ulong) | |
| 1995/1213 | { | |
| 1996/0531 | volatile struct { Dstate *s; } s; | |
| 1995/1218 | Block *b; | |
| 1995/1217 |
| |
| 2000/0913 | uchar consumed[3]; int nconsumed; | |
| 1996/1029 | int len, pad; | |
| 1995/1217 | ||
| 1996/1029 | s.s = dstate[CONV(c->qid)]; | |
| 2000/0325/sys/src/9/port/devssl.c:492,500 – 2000/0913/sys/src/9/port/devssl.c:523,533 | ||
| 1996/1029 | if(s.s->state == Sincomplete) | |
| 1995/1217 | error(Ebadusefd); | |
| 2000/0913 | nconsumed = 0; | |
| 1995/1217 | if(waserror()){ | |
| 2000/0913 | if(strcmp(up->error, Eintr) != 0 && nconsumed) regurgitate(s.s, consumed, nconsumed); | |
| 1996/0531 | qunlock(&s.s->in.q); | |
| 1996/1029 |
| |
| 1995/1217 | nexterror(); | |
| 1995/1213 | } | |
| 1996/0531 | qlock(&s.s->in.q); | |
| 2000/0325/sys/src/9/port/devssl.c:502,559 – 2000/0913/sys/src/9/port/devssl.c:535,606 | ||
| 1996/1029 | if(s.s->processed == 0){ | |
| 1995/1217 | /* read in the whole message */ | |
| 1996/1029 | ensure(s.s, &s.s->unprocessed, 2); | |
| 1995/1217 |
| |
| 2000/0913 | consume(&s.s->unprocessed, consumed, 2); nconsumed = 2; if(consumed[0] & 0x80){ len = ((consumed[0] & 0x7f)<<8) | consumed[1]; | |
| 1996/1029 | ensure(s.s, &s.s->unprocessed, len); | |
| 1995/1217 | pad = 0; } else { | |
| 2000/0913 | len = ((consumed[0] & 0x3f)<<8) | consumed[1]; | |
| 1996/1029 | ensure(s.s, &s.s->unprocessed, len+1); | |
| 1995/1217 |
| |
| 2000/0913 | consume(&s.s->unprocessed, &consumed[2], 1); pad = consumed[2]; | |
| 1996/1029 | if(pad > len){ print("pad %d buf len %d\n", pad, len); error("bad pad in ssl message"); } | |
| 1995/1217 | } | |
| 2000/0913 | USED(nconsumed); nconsumed = 0; | |
| 1995/1217 | ||
| 1996/1029 |
| |
| 2000/0913 | /* if an Eintr happens after this, we screwed. Make * sure nothing we call can sleep. Luckily, allocb * won't sleep, it'll just error out. */ | |
| 1995/1217 | ||
| 2000/0913 | /* grab the next message and decode/decrypt it */ b = qremove(&s.s->unprocessed, len, 0); | |
| 1996/1029 | if(waserror()){ qunlock(&s.s->in.ctlq); | |
| 2000/0913 | if(b != nil) freeb(b); | |
| 1996/1029 | nexterror(); | |
| 1995/1217 | } | |
| 1996/1029 | qlock(&s.s->in.ctlq); switch(s.s->state){ case Sencrypting: | |
| 2000/0913 | b = decryptb(s.s, b); | |
| 1996/1029 | break; case Sdigesting: | |
| 2000/0913 | b = pullupblock(b, s.s->diglen); if(b == nil) | |
| 1996/1029 | error("ssl message too short"); | |
| 2000/0913 | checkdigestb(s.s, b); b->rp += s.s->diglen; | |
| 1996/1029 | break; | |
| 1997/0618 | case Sdigenc: | |
| 2000/0913 | b = decryptb(s.s, b); b = pullupblock(b, s.s->diglen); if(b == nil) | |
| 1997/0618 | error("ssl message too short"); | |
| 2000/0913 | checkdigestb(s.s, b); b->rp += s.s->diglen; | |
| 1998/0501 | len -= s.s->diglen; | |
| 1997/0618 | break; | |
| 1995/1218 | } | |
| 1997/0618 |
| |
| 1996/1029 |
| |
| 1995/1217 | /* remove pad */ | |
| 1996/1029 | if(pad) | |
| 2000/0913 | s.s->processed = qremove(&b, len - pad, 1); else s.s->processed = b; b = nil; s.s->in.mid++; qunlock(&s.s->in.ctlq); poperror(); USED(nconsumed); | |
| 1995/1217 | } | |
| 1996/1029 | /* return at most what was asked for */ | |
| 2000/0325/sys/src/9/port/devssl.c:626,632 – 2000/0913/sys/src/9/port/devssl.c:673,682 | ||
| 1996/1029 | } /* | |
| 1995/1215 |
| |
| 2000/0913 | * use SSL record format, add in count, digest and/or encrypt. * the write is interruptable. if it is interrupted, we'll * get out of sync with the far side. not much we can do about * it since we don't know if any bytes have been written. | |
| 1995/1215 | */ | |
| 1997/0327 | static long | |
| 1995/1215 | sslbwrite(Chan *c, Block *b, ulong offset) | |
| 2000/0325/sys/src/9/port/devssl.c:646,656 – 2000/0913/sys/src/9/port/devssl.c:696,708 | ||
| 1995/1215 | error(Ebadusefd); | |
| 1996/1029 | } | |
| 1995/1215 | ||
| 2000/0913 | nb = nil; | |
| 1995/1215 | if(waserror()){ | |
| 1996/0531 | qunlock(&s.s->out.q); | |
| 2000/0913 | if(bb.b != nil) | |
| 1996/0531 | freeb(bb.b); | |
| 1996/1029 |
| |
| 2000/0913 | if(nb != nil) freeb(nb); | |
| 1995/1215 | nexterror(); } | |
| 1996/0531 | qlock(&s.s->out.q); | |