krb5_encode.c revision 159d09a20817016f09b3ea28d1bdada4a336bb91
/*
*
* Copyright 1994 by the Massachusetts Institute of Technology.
* All Rights Reserved.
*
* Export of this software from the United States of America may
* require a specific license from the United States Government.
* It is the responsibility of any person or organization contemplating
* export to obtain such a license before exporting.
*
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, provided that the above copyright
* notice appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation, and that
* the name of M.I.T. not be used in advertising or publicity pertaining
* to distribution of the software without specific, written prior
* permission. Furthermore if you modify this software you must label
* your software as modified software and not distribute it in such a
* fashion that it might be confused with the original M.I.T. software.
* M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
*/
#include "k5-int.h"
#include "asn1_k_encode.h"
#include "asn1_encode.h"
#include "krbasn1.h"
#include "asn1buf.h"
#include "asn1_make.h"
/**************** Macros (these save a lot of typing) ****************/
/**** krb5 macros ****/
#if 0
{
krb5_setup();
...
/* for OPTIONAL fields */
/* for string fields (these encoders take an additional argument,
the length of the string) */
/* if you really have to do things yourself... */
...
krb5_makeseq();
krb5_cleanup();
}
#endif
/* setup() -- create and initialize bookkeeping variables
retval: stores error codes returned from subroutines
buf: the coding buffer
length: length of the most-recently produced encoding
sum: cumulative length of the entire encoding */
#define krb5_setup()\
\
\
/* krb5_addfield -- add a field, or component, to the encoding */
if(retval){\
asn1buf_destroy(&buf);\
return retval; }\
if(retval){\
asn1buf_destroy(&buf);\
return retval; }\
/* krb5_addlenfield -- add a field whose length must be separately specified */
if(retval){\
asn1buf_destroy(&buf);\
return retval; }\
if(retval){\
asn1buf_destroy(&buf);\
return retval; }\
/* form a sequence (by adding a sequence header to the current encoding) */
#define krb5_makeseq()\
if(retval){\
asn1buf_destroy(&buf);\
return retval; }\
/* add an APPLICATION class tag to the current encoding */
#define krb5_apptag(num)\
if(retval){\
asn1buf_destroy(&buf);\
return retval; }\
/* produce the final output and clean up the workspace */
#define krb5_cleanup()\
if(retval){\
asn1buf_destroy(&buf);\
return retval; }\
if(retval){\
return retval; }\
\
return 0
{
krb5_setup();
/* authorization-data[8] AuthorizationData OPTIONAL */
&length);
if(retval){
return retval; }
if(retval){
return retval; }
}
/* seq-number[7] INTEGER OPTIONAL */
if(rep->seq_number != 0)
/* subkey[6] EncryptionKey OPTIONAL */
/* ctime[5] KerberosTime */
/* cusec[4] INTEGER */
/* cksum[3] Checksum OPTIONAL */
/* cname[2] PrincipalName */
/* crealm[1] Realm */
/* authenticator-vno[0] INTEGER */
/* Authenticator ::= [APPLICATION 2] SEQUENCE */
krb5_makeseq();
krb5_apptag(2);
krb5_cleanup();
}
{
krb5_setup();
/* enc-part[3] EncryptedData */
/* sname [2] PrincipalName */
/* realm [1] Realm */
/* tkt-vno [0] INTEGER */
/* Ticket ::= [APPLICATION 1] SEQUENCE */
krb5_makeseq();
krb5_apptag(1);
krb5_cleanup();
}
{
krb5_setup();
/* keyvalue[1] OCTET STRING */
/* enctype[0] INTEGER */
/* EncryptionKey ::= SEQUENCE */
krb5_makeseq();
krb5_cleanup();
}
{
krb5_setup();
/* authorization-data[10] AuthorizationData OPTIONAL */
/* caddr[9] HostAddresses OPTIONAL */
/* renew-till[8] KerberosTime OPTIONAL */
/* endtime[7] KerberosTime */
/* starttime[6] KerberosTime OPTIONAL */
/* authtime[5] KerberosTime */
/* transited[4] TransitedEncoding */
/* cname[3] PrincipalName */
/* crealm[2] Realm */
/* key[1] EncryptionKey */
/* flags[0] TicketFlags */
/* EncTicketPart ::= [APPLICATION 3] SEQUENCE */
krb5_makeseq();
krb5_apptag(3);
krb5_cleanup();
}
{
krb5_apptag(26);
#else
/* XXX WRONG!!! Should use 25 || 26, not the outer KDC_REP tags! */
else return KRB5_BADMSGTYPE;
#endif
krb5_cleanup();
}
/* yes, the translation is identical to that used for KDC__REP */
{
krb5_setup();
/* AS-REP ::= [APPLICATION 11] KDC-REP */
krb5_apptag(11);
krb5_cleanup();
}
/* yes, the translation is identical to that used for KDC__REP */
{
krb5_setup();
/* TGS-REP ::= [APPLICATION 13] KDC-REP */
krb5_apptag(13);
krb5_cleanup();
}
{
krb5_setup();
/* authenticator[4] EncryptedData */
/* ticket[3] Ticket */
/* ap-options[2] APOptions */
/* msg-type[1] INTEGER */
/* pvno[0] INTEGER */
/* AP-REQ ::= [APPLICATION 14] SEQUENCE */
krb5_makeseq();
krb5_apptag(14);
krb5_cleanup();
}
{
krb5_setup();
/* enc-part[2] EncryptedData */
/* msg-type[1] INTEGER */
/* pvno[0] INTEGER */
/* AP-REP ::= [APPLICATION 15] SEQUENCE */
krb5_makeseq();
krb5_apptag(15);
krb5_cleanup();
}
{
krb5_setup();
/* seq-number[3] INTEGER OPTIONAL */
if(rep->seq_number)
/* subkey[2] EncryptionKey OPTIONAL */
/* cusec[1] INTEGER */
/* ctime[0] KerberosTime */
/* EncAPRepPart ::= [APPLICATION 27] SEQUENCE */
krb5_makeseq();
krb5_apptag(27);
krb5_cleanup();
}
{
krb5_setup();
/* AS-REQ ::= [APPLICATION 10] KDC-REQ */
krb5_apptag(10);
krb5_cleanup();
}
{
krb5_setup();
/* TGS-REQ ::= [APPLICATION 12] KDC-REQ */
krb5_apptag(12);
krb5_cleanup();
}
{
krb5_setup();
krb5_cleanup();
}
{
krb5_setup();
/* cksum[3] Checksum */
/* safe-body[2] KRB-SAFE-BODY */
/* msg-type[1] INTEGER */
/* pvno[0] INTEGER */
/* KRB-SAFE ::= [APPLICATION 20] SEQUENCE */
krb5_makeseq();
krb5_apptag(20);
krb5_cleanup();
}
/*
* encode_krb5_safe_with_body
*
* Like encode_krb5_safe(), except takes a saved KRB-SAFE-BODY
* encoding to avoid problems with re-encoding.
*/
{
krb5_setup();
return ASN1_MISSING_FIELD;
}
/* cksum[3] Checksum */
/* safe-body[2] KRB-SAFE-BODY */
/* msg-type[1] INTEGER */
/* pvno[0] INTEGER */
/* KRB-SAFE ::= [APPLICATION 20] SEQUENCE */
krb5_makeseq();
krb5_apptag(20);
krb5_cleanup();
}
{
krb5_setup();
/* enc-part[3] EncryptedData */
/* msg-type[1] INTEGER */
/* pvno[0] INTEGER */
/* KRB-PRIV ::= [APPLICATION 21] SEQUENCE */
krb5_makeseq();
krb5_apptag(21);
krb5_cleanup();
}
{
krb5_setup();
/* r-address[5] HostAddress OPTIONAL -- recip's addr */
/* s-address[4] HostAddress -- sender's addr */
/* seq-number[3] INTEGER OPTIONAL */
if(rep->seq_number)
/* usec[2] INTEGER OPTIONAL */
/* timestamp[1] KerberosTime OPTIONAL */
}
/* user-data[0] OCTET STRING */
/* EncKrbPrivPart ::= [APPLICATION 28] SEQUENCE */
krb5_makeseq();
krb5_apptag(28);
krb5_cleanup();
}
{
krb5_setup();
/* enc-part[3] EncryptedData */
/* tickets[2] SEQUENCE OF Ticket */
/* msg-type[1] INTEGER, -- KRB_CRED */
/* pvno[0] INTEGER */
/* KRB-CRED ::= [APPLICATION 22] SEQUENCE */
krb5_makeseq();
krb5_apptag(22);
krb5_cleanup();
}
{
krb5_setup();
/* r-address[5] HostAddress OPTIONAL */
/* s-address[4] HostAddress OPTIONAL */
/* usec[3] INTEGER OPTIONAL */
/* timestamp[2] KerberosTime OPTIONAL */
}
/* nonce[1] INTEGER OPTIONAL */
/* ticket-info[0] SEQUENCE OF KrbCredInfo */
/* EncKrbCredPart ::= [APPLICATION 29] SEQUENCE */
krb5_makeseq();
krb5_apptag(29);
krb5_cleanup();
}
{
krb5_setup();
/* e-data[12] OCTET STRING OPTIONAL */
/* e-text[11] GeneralString OPTIONAL */
/* sname[10] PrincipalName -- Correct name */
/* realm[9] Realm -- Correct realm */
/* cname[8] PrincipalName OPTIONAL */
/* crealm[7] Realm OPTIONAL */
}
/* error-code[6] INTEGER */
/* susec[5] INTEGER */
/* stime[4] KerberosTime */
/* cusec[3] INTEGER OPTIONAL */
/* ctime[2] KerberosTime OPTIONAL */
/* msg-type[1] INTEGER */
/* pvno[0] INTEGER */
/* KRB-ERROR ::= [APPLICATION 30] SEQUENCE */
krb5_makeseq();
krb5_apptag(30);
krb5_cleanup();
}
{
unsigned int length;
&length);
krb5_cleanup();
}
{
unsigned int length;
krb5_cleanup();
}
{
krb5_setup();
/* method-data[1] OctetString OPTIONAL */
/* method-type[0] Integer */
krb5_makeseq();
krb5_cleanup();
}
{
krb5_setup();
krb5_cleanup();
}
{
krb5_setup();
krb5_cleanup();
}
{
krb5_setup();
krb5_cleanup();
}
{
krb5_setup();
/* pausec[1] INTEGER OPTIONAL */
/* patimestamp[0] KerberosTime, -- client's time */
krb5_makeseq();
krb5_cleanup();
}
/* Sandia Additions */
{
krb5_setup();
krb5_cleanup();
}
{
krb5_setup();
krb5_addfield((const passwd_phrase_element**)rep->element,1,asn1_encode_sequence_of_passwdsequence);
krb5_makeseq();
krb5_cleanup();
}
{
krb5_setup();
krb5_cleanup();
}
/* sam preauth additions */
{
krb5_setup();
krb5_cleanup();
}
{
krb5_setup();
krb5_cleanup();
}
krb5_error_code encode_krb5_sam_challenge_2_body(const krb5_sam_challenge_2_body *rep, krb5_data **code)
{
krb5_setup();
krb5_cleanup();
}
{
krb5_setup();
krb5_cleanup();
}
krb5_error_code encode_krb5_enc_sam_response_enc(const krb5_enc_sam_response_enc *rep, krb5_data **code)
{
krb5_setup();
krb5_cleanup();
}
krb5_error_code encode_krb5_enc_sam_response_enc_2(const krb5_enc_sam_response_enc_2 *rep, krb5_data **code)
{
krb5_setup();
krb5_cleanup();
}
{
krb5_setup();
krb5_cleanup();
}
{
krb5_setup();
krb5_cleanup();
}
krb5_error_code encode_krb5_predicted_sam_response(const krb5_predicted_sam_response *rep, krb5_data **code)
{
krb5_setup();
krb5_cleanup();
}
{
/* Macros really want us to have a variable called rep which we do not need*/
const char *rep = "dummy string";
krb5_setup();
/* Solaris Kerberos */
krb5_makeseq();
krb5_cleanup();
}
{
krb5_setup();
krb5_cleanup();
}
krb5_error_code encode_krb5_pa_pk_as_req_draft9(const krb5_pa_pk_as_req_draft9 *rep, krb5_data **code)
{
krb5_setup();
krb5_cleanup();
}
{
krb5_setup();
krb5_cleanup();
}
krb5_error_code encode_krb5_pa_pk_as_rep_draft9(const krb5_pa_pk_as_rep_draft9 *rep, krb5_data **code)
{
krb5_setup();
krb5_cleanup();
}
{
krb5_setup();
krb5_cleanup();
}
{
krb5_setup();
krb5_cleanup();
}
{
krb5_setup();
krb5_cleanup();
}
{
krb5_setup();
krb5_cleanup();
}
krb5_error_code encode_krb5_reply_key_pack_draft9(const krb5_reply_key_pack_draft9 *rep, krb5_data **code)
{
krb5_setup();
krb5_cleanup();
}
krb5_error_code encode_krb5_td_trusted_certifiers(const krb5_external_principal_identifier **rep, krb5_data **code)
{
krb5_setup();
krb5_cleanup();
}
{
krb5_setup();
krb5_cleanup();
}
krb5_error_code encode_krb5_td_dh_parameters(const krb5_algorithm_identifier **rep, krb5_data **code)
{
krb5_setup();
krb5_cleanup();
}