- * process the incoming Authentication chunk * return codes: * -1 on any authentication error * 0 on authentication verification */
| 1587 | * 0 on authentication verification |
| 1588 | */ |
| 1589 | int |
| 1590 | sctp_handle_auth(struct sctp_tcb *stcb, struct sctp_auth_chunk *auth, |
| 1591 | struct mbuf *m, uint32_t offset) |
| 1592 | { |
| 1593 | uint16_t chunklen; |
| 1594 | uint16_t shared_key_id; |
| 1595 | uint16_t hmac_id; |
| 1596 | sctp_sharedkey_t *skey; |
| 1597 | uint32_t digestlen; |
| 1598 | uint8_t digest[SCTP_AUTH_DIGEST_LEN_MAX]; |
| 1599 | uint8_t computed_digest[SCTP_AUTH_DIGEST_LEN_MAX]; |
| 1600 | |
| 1601 | /* auth is checked for NULL by caller */ |
| 1602 | chunklen = ntohs(auth->ch.chunk_length); |
| 1603 | if (chunklen < sizeof(*auth)) { |
| 1604 | SCTP_STAT_INCR(sctps_recvauthfailed); |
| 1605 | return (-1); |
| 1606 | } |
| 1607 | SCTP_STAT_INCR(sctps_recvauth); |
| 1608 | |
| 1609 | /* get the auth params */ |
| 1610 | shared_key_id = ntohs(auth->shared_key_id); |
| 1611 | hmac_id = ntohs(auth->hmac_id); |
| 1612 | SCTPDBG(SCTP_DEBUG_AUTH1, |
| 1613 | "SCTP AUTH Chunk: shared key %u, HMAC id %u\n", |
| 1614 | shared_key_id, hmac_id); |
| 1615 | |
| 1616 | /* is the indicated HMAC supported? */ |
| 1617 | if (!sctp_auth_is_supported_hmac(stcb->asoc.local_hmacs, hmac_id)) { |
| 1618 | struct mbuf *op_err; |
| 1619 | struct sctp_error_auth_invalid_hmac *cause; |
| 1620 | |
| 1621 | SCTP_STAT_INCR(sctps_recvivalhmacid); |
| 1622 | SCTPDBG(SCTP_DEBUG_AUTH1, |
| 1623 | "SCTP Auth: unsupported HMAC id %u\n", |
| 1624 | hmac_id); |
| 1625 | /* |
| 1626 | * report this in an Error Chunk: Unsupported HMAC |
| 1627 | * Identifier |
| 1628 | */ |
| 1629 | op_err = sctp_get_mbuf_for_msg(sizeof(struct sctp_error_auth_invalid_hmac), |
| 1630 | 0, M_NOWAIT, 1, MT_HEADER); |
| 1631 | if (op_err != NULL) { |
| 1632 | /* pre-reserve some space */ |
| 1633 | SCTP_BUF_RESV_UF(op_err, sizeof(struct sctp_chunkhdr)); |
| 1634 | /* fill in the error */ |
| 1635 | cause = mtod(op_err, struct sctp_error_auth_invalid_hmac *); |
| 1636 | cause->cause.code = htons(SCTP_CAUSE_UNSUPPORTED_HMACID); |
| 1637 | cause->cause.length = htons(sizeof(struct sctp_error_auth_invalid_hmac)); |
| 1638 | cause->hmac_id = ntohs(hmac_id); |
| 1639 | SCTP_BUF_LEN(op_err) = sizeof(struct sctp_error_auth_invalid_hmac); |
| 1640 | /* queue it */ |
| 1641 | sctp_queue_op_err(stcb, op_err); |
| 1642 | } |
| 1643 | return (-1); |
| 1644 | } |
| 1645 | /* get the indicated shared key, if available */ |
| 1646 | if ((stcb->asoc.authinfo.recv_key == NULL) || |
no test coverage detected