1.\" $OpenBSD: keynote.3,v 1.54 2017/07/05 11:43:09 schwarze Exp $ 2.\" 3.\" The author of this code is Angelos D. Keromytis (angelos@dsl.cis.upenn.edu) 4.\" 5.\" This code was written by Angelos D. Keromytis in Philadelphia, PA, USA, 6.\" in April-May 1998 7.\" 8.\" Copyright (C) 1998, 1999 by Angelos D. Keromytis. 9.\" 10.\" Permission to use, copy, and modify this software with or without fee 11.\" is hereby granted, provided that this entire notice is included in 12.\" all copies of any software which is or includes a copy or 13.\" modification of this software. 14.\" You may use this code under the GNU public license if you so wish. Please 15.\" contribute changes back to the author. 16.\" 17.\" THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR 18.\" IMPLIED WARRANTY. IN PARTICULAR, THE AUTHORS MAKES NO 19.\" REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE 20.\" MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR 21.\" PURPOSE. 22.\" 23.Dd $Mdocdate: July 5 2017 $ 24.Dt KN_INIT 3 25.\" .TH KeyNote 3 local 26.Os 27.Sh NAME 28.Nm kn_init , 29.Nm kn_add_assertion , 30.Nm kn_remove_assertion , 31.Nm kn_add_action , 32.Nm kn_remove_action , 33.Nm kn_add_authorizer , 34.Nm kn_remove_authorizer , 35.Nm kn_do_query , 36.Nm kn_get_failed , 37.Nm kn_cleanup_action_environment , 38.Nm kn_close , 39.Nm kn_query , 40.Nm kn_read_asserts , 41.Nm kn_keycompare , 42.Nm kn_get_authorizer , 43.Nm kn_get_licensees , 44.Nm kn_encode_base64 , 45.Nm kn_decode_base64 , 46.Nm kn_encode_hex , 47.Nm kn_decode_hex , 48.Nm kn_encode_key , 49.Nm kn_decode_key , 50.Nm kn_sign_assertion , 51.Nm kn_verify_assertion , 52.Nm kn_free_key , 53.Nm kn_get_string 54.Nd a trust-management system library 55.Sh SYNOPSIS 56.In sys/types.h 57.In regex.h 58.In keynote.h 59.Bd -literal 60struct environment { 61 char *env_name; 62 char *env_value; 63 int env_flags; 64 regex_t env_regex; 65 struct environment *env_next; 66}; 67 68struct keynote_deckey { 69 int dec_algorithm; 70 void *dec_key; 71}; 72 73struct keynote_binary { 74 int bn_len; 75 char *bn_key; 76}; 77 78struct keynote_keylist { 79 int key_alg; 80 void *key_key; 81 char *key_stringkey; 82 struct keynote_keylist *key_next; 83}; 84.Ed 85.Vt extern int keynote_errno; 86.Ft int 87.Fn kn_init "void" 88.Ft int 89.Fn kn_add_assertion "int sessid" "char *assertion" "int len" "int flags" 90.Ft int 91.Fn kn_remove_assertion "int sessid" "int assertid" 92.Ft int 93.Fn kn_add_action "int sessid" "char *name" "char *value" "int flags" 94.Ft int 95.Fn kn_remove_action "int sessid" "char *name" 96.Ft int 97.Fn kn_add_authorizer "int sessid" "char *principal" 98.Ft int 99.Fn kn_remove_authorizer "int sessid" "char *principal" 100.Ft int 101.Fn kn_do_query "int sessid" "char **returnvalues" "int numvalues" 102.Ft int 103.Fn kn_get_failed "int sessid" "int type" "int seq" 104.Ft int 105.Fn kn_cleanup_action_environment "int sessid" 106.Ft int 107.Fn kn_close "int sessid" 108.Ft int 109.Fo kn_query 110.Fa "struct environment *env" 111.Fa "char **returnvalues" 112.Fa "int numvalues" 113.Fa "char **trusted" 114.Fa "int *trustedlen" 115.Fa "int numtrusted" 116.Fa "char **untrusted" 117.Fa "int *untrustedlen" 118.Fa "int numuntrusted" 119.Fa "char **authorizers" 120.Fa "int numauthorizers" 121.Fc 122.Ft char ** 123.Fn kn_read_asserts "char *array" "int arraylen" "int *numassertions" 124.Ft int 125.Fn kn_keycompare "void *key1" "void *key2" "int algorithm" 126.Ft void * 127.Fn kn_get_authorizer "int sessid" "int assertid" "int *algorithm" 128.Ft struct keynote_keylist * 129.Fn kn_get_licensees "int sessid" "int assertid" 130.Ft int 131.Fn kn_encode_base64 "unsigned char const *src" "unsigned int srclen" "char *dst" "unsigned int dstlen" 132.Ft int 133.Fn kn_decode_base64 "char const *src" "unsigned char *dst" "unsigned int dstlen" 134.Ft int 135.Fn kn_encode_hex "unsigned char *src" "char **dst" "int srclen" 136.Ft int 137.Fn kn_decode_hex "char *src" "char **dst" 138.Ft char * 139.Fn kn_encode_key "struct keynote_deckey *dc" "int iencoding" "int encoding" "int keytype" 140.Ft int 141.Fn kn_decode_key "struct keynote_deckey *dc" "char *key" "int keytype" 142.Ft char * 143.Fn kn_sign_assertion "char *assertion" "int len" "char *key" "char *algorithm" "int vflag" 144.Ft int 145.Fn kn_verify_assertion "char *assertion" "int len" 146.Ft void 147.Fn kn_free_key "struct keynote_deckey *" 148.Ft char * 149.Fn kn_get_string "char *" 150.Fd Link options: -lkeynote -lm -lcrypto 151.Sh DESCRIPTION 152For more details on 153.Nm keynote , 154see RFC 2704. 155.Pp 156.Va keynote_errno 157contains an error code if some library call failed. 158Failed calls return \-1 (if their return value is integer), or 159.Dv NULL 160(if their return value is a pointer) and set 161.Va keynote_errno . 162The defined error codes are: 163.Bl -tag -width "ERROR_NOTFOUND" -offset indent 164.It Li ERROR_MEMORY 165Some memory allocation or usage error was encountered. 166.It Li ERROR_SYNTAX 167Some syntactic or logical error was encountered. 168.It Li ERROR_NOTFOUND 169One of the arguments referred to a nonexistent structure or entry. 170.El 171.Pp 172If no errors were encountered, 173.Va keynote_errno 174will be set to 0. 175This variable should be reset to 0 if an error was encountered, 176prior to calling other library routines. 177.Pp 178The main interface to 179.Nm 180is centered around the concept of a session. 181A session describes a collection of policies, assertions, action 182authorizers, return values, and action attributes that the 183.Nm 184system uses to evaluate a query. 185Information is not shared between sessions. 186Policies, credentials, action authorizers, and action 187attributes can be added or deleted at any point during the lifetime of 188a session. 189Furthermore, an application can discover which assertions failed to be 190evaluated, and in what way, during a query. 191.Pp 192For those applications that only need to do a simple query, there 193exists a single call that takes as arguments all the necessary 194information and performs all the necessary steps. 195This is essentially a wrapper that calls the session API functions as 196necessary. 197.Pp 198Finally, there exist functions for doing ASCII to hexadecimal and 199Base64 encoding (and vice versa), for encoding/decoding keys between 200ASCII and binary formats, and for signing and verifying assertions. 201.Pp 202The description of all 203.Nm 204library functions follows. 205.Pp 206.Fn kn_init 207creates a new 208.Nm 209session, and performs any necessary initializations. 210On success, this function returns the new session ID, which is used by 211all subsequent calls with a 212.Fa sessid 213argument. 214On failure, it returns \-1 and sets 215.Va keynote_errno 216to 217.Er ERROR_MEMORY . 218.Pp 219.Fn kn_add_assertion 220adds the assertion pointed to by the array 221.Fa assertion , 222of length 223.Fa len 224in the session identified by 225.Fa sessid . 226The first argument can be discarded after the call to this function. 227The following flags are defined: 228.Bl -tag -width ASSERT_FLAG_LOCAL -offset indent 229.It ASSERT_FLAG_LOCAL 230Mark this assertion as ultimately trusted. 231Trusted assertions need not be signed, and the 232.Fa Authorizer 233and 234.Fa Licensees 235fields can have non-key entries. 236.El 237.Pp 238At least one (trusted) assertion should have 239.Dv POLICY 240as the 241.Fa Authorizer . 242On success, this function will return an assertion ID which can be 243used to remove the assertion from the session, by using 244.Fn kn_remove_assertion . 245On failure, \-1 is returned, and 246.Va keynote_errno 247is set to 248.Er ERROR_NOTFOUND 249if the session was not found, 250.Er ERROR_SYNTAX 251if the assertion was syntactically incorrect, or 252.Er ERROR_MEMORY 253if necessary memory could not be allocated. 254.Pp 255.Fn kn_remove_assertion 256removes the assertion identified by 257.Fa assertid 258from the session identified by 259.Fa sessid . 260On success, this function returns 0. 261On failure, it returns \-1 and sets 262.Va keynote_errno 263to 264.Er ERROR_NOTFOUND . 265.Pp 266.Fn kn_add_action 267inserts the variable 268.Fa name 269in the action environment of session 270.Fa sessid , 271with the value 272.Fa value . 273The same attribute may be added more than once, but only the last 274instance will be used (memory resources are consumed however). 275.Pp 276The 277.Fa flags 278specified are formed by or'ing the following values: 279.Bl -tag -width ENVIRONMENT_FLAG_REGEX -offset indent 280.It ENVIRONMENT_FLAG_FUNC 281In this case, 282.Fa value 283is a pointer to a function that takes as argument a string and returns 284a string. 285This is used to implement callbacks for getting action attribute values. 286The argument passed to such a callback function is a string identifying 287the action attribute whose value is requested, and should return a pointer 288to string containing that value (this pointer will not be freed by the 289library), the empty string if the value was not found, or a 290.Dv NULL 291to indicate an error (and may set 292.Va keynote_errno 293appropriately). 294Prior to first use (currently, at the time the attribute is added to the 295session environment), such functions are called with 296.Dv KEYNOTE_CALLBACK_INITIALIZE 297as the argument (defined in keynote.h) so that they can perform any special 298initializations. 299Furthermore, when the session is deleted, all such functions will be called 300with 301.Dv KEYNOTE_CALLBACK_CLEANUP 302to perform any special cleanup (such as free any allocated memory). 303A function may be called with either of these arguments more than once, 304if it has been defined as the callback function for more than one attribute. 305.It ENVIRONMENT_FLAG_REGEX 306In this case, 307.Fa name 308is a regular expression that may match more than one attribute. 309In case of conflict between a regular expression and a 310.Dq simple 311attribute, the latter will be given priority. 312In case of conflict between two regular expression attributes, the one added 313later will be given priority. 314A callback function should never change the current 315.Nm 316session, start/invoke/operate on another session, or call one of the 317session-API functions. 318.El 319.Pp 320The combination of the two flags may be used to specify callback 321functions that handle large sets of attributes (even to the extent of 322having one callback function handling all attribute references). 323This is particularly useful when the action attribute set is particularly 324large. 325.Pp 326On success, 327.Fn kn_add_action 328returns 0. 329On failure, it returns \-1 and sets 330.Va keynote_errno 331to 332.Er ERROR_NOTFOUND 333if the session was not found, 334.Er ERROR_SYNTAX 335if the 336.Fa name 337was invalid (e.g., started with an underscore character) or was 338.Dv NULL , 339or 340.Er ERROR_MEMORY 341if necessary memory could not be allocated. 342.Pp 343.Fn kn_remove_action 344removes action attribute 345.Fa name 346from the environment of session 347.Fa sessid . 348Notice that if more than one instances of 349.Fa name 350exist, only the one added last will be deleted. 351On success, this function returns 0. 352On failure, it returns \-1 and 353.Va keynote_errno 354is set to 355.Er ERROR_NOTFOUND 356if the session or the attribute were not found, or 357.Er ERROR_SYNTAX 358if the name was invalid. 359If the attribute value was a callback, that function will be called with 360the define 361.Dv KEYNOTE_CALLBACK_CLEANUP 362as the argument. 363.Pp 364.Fn kn_add_authorizer 365adds the principal pointed to by 366.Fa principal 367to the action authorizers list of session 368.Fa sessid . 369The principal is typically an ASCII-encoded key. 370On success, this function will return 0. 371On failure, it returns \-1 and sets 372.Va keynote_errno 373to 374.Er ERROR_NOTFOUND 375if the session was not found, 376.Er ERROR_SYNTAX 377if the encoding was invalid, or 378.Er ERROR_MEMORY 379if necessary memory could not be allocated. 380.Pp 381.Fn kn_remove_authorizer 382removes 383.Fa principal 384from the action authorizer list of session 385.Fa sessid . 386On success, this function returns 0. 387On failure, it returns \-1 and sets 388.Va keynote_errno 389to 390.Er ERROR_NOTFOUND 391if the session was not found. 392.Pp 393.Fn kn_do_query 394evaluates the request based on the assertions, action attributes, and 395action authorizers added to session 396.Fa sessid . 397.Fa returnvalues 398is an ordered array of strings that contain the return values. 399The lowest-ordered return value is contained in 400.Fa returnvalues Ns Bq 0 , 401and the highest-ordered value is 402.Fa returnvalues Ns Bq Fa numvalues No \- 1 . 403If 404.Fa returnvalues 405is 406.Dv NULL , 407the 408.Fa returnvalues 409from the previous call to 410.Fn kn_do_query 411will be used. 412The programmer SHOULD NOT free 413.Fa returnvalues 414after the call to 415.Fn kn_do_query 416if this feature is used, as the array is not replicated internally. 417On success, this function returns an index into the 418.Fa returnvalues 419array. 420On failure, it returns \-1 and sets 421.Va keynote_errno 422to 423.Er ERROR_NOTFOUND 424if the session was not found or the authorizers list was empty, 425.Er ERROR_SYNTAX 426if no 427.Fa returnvalues 428have been specified, or 429.Er ERROR_MEMORY 430if necessary memory could not be allocated. 431.Pp 432.Fn kn_get_failed 433returns the assertion ID of the 434.Fa num'th 435assertion (starting from zero) in session 436.Fa sessid 437that was somehow invalid during evaluation. 438This function is typically called after 439.Fn kn_do_query 440is used to evaluate a request. 441.Fa type 442specifies the type of failure the application is interested in. 443It can be set to: 444.Bl -tag -width KEYNOTE_ERROR_SIGNATURE -offset indent 445.It KEYNOTE_ERROR_ANY 446to indicate interest in any error. 447.It KEYNOTE_ERROR_SYNTAX 448for syntactic or semantic errors. 449.It KEYNOTE_ERROR_MEMORY 450for memory-related problems. 451.It KEYNOTE_ERROR_SIGNATURE 452if the assertion could not be cryptographically verified. 453.El 454.Pp 455These values are defined in keynote.h. 456An application can then delete the offending assertion using 457.Fn kn_remove_assertion . 458For example, to remove all assertion whose signature failed, an application 459could do something like: 460.Bd -literal 461 while ((assertid = kn_get_failed(sessid, KEYNOTE_ERROR_SIGNATURE, 0) 462 != -1) 463 kn_remove_assertion(sessid, assertid); 464.Ed 465.Pp 466On success, 467.Fn kn_get_failed 468returns an assertion ID. 469On failure, or when no assertion matching the given criteria is found, 470it returns \-1 and set 471.Va keynote_errno 472to 473.Er ERROR_NOTFOUND . 474.Pp 475.Fn kn_cleanup_action_environment 476removes all action attributes from the action environment of session 477.Fa sessid . 478It returns 0 on success. 479.Pp 480.Fn kn_close 481closes session 482.Fa sessid 483and frees all related resources, deleting action attributes, action 484authorizers, and assertions. 485On success, this function returns 0. 486On failure, it returns \-1 and sets 487.Va keynote_errno 488to 489.Er ERROR_NOTFOUND 490if the session was not found. 491.Pp 492.Fn kn_read_asserts 493parses the string 494.Fa array 495of length 496.Fa arraylen 497and returns an array of pointers to strings containing copies of 498the assertions found in 499.Fa array . 500Both the array of pointers and the strings are allocated by 501.Fn kn_read_asserts 502dynamically, and thus should be freed by the programmer when they are 503no longer needed. 504.Fa numassertions 505contains the number of assertions (and thus strings in the returned 506array) found in 507.Fa array . 508On failure, this function returns 509.Dv NULL 510and sets 511.Va keynote_errno 512to 513.Er ERROR_MEMORY 514if necessary memory could not be allocated, or 515.Er ERROR_SYNTAX 516if 517.Fa array 518was 519.Dv NULL . 520Note that if there were no assertions found in 521.Fa array , 522a valid pointer will be returned, but 523.Fa numassertions 524will contain the value zero on return. 525The returned pointer should be freed by the programmer. 526.Pp 527.Fn kn_keycompare 528compares 529.Fa key1 530and 531.Fa key2 532(which must be of the same 533.Fa algorithm ) 534and returns 1 if equal and 0 otherwise. 535.Pp 536.Fn kn_get_authorizer 537returns the authorizer key (in binary format) for assertion 538.Fa assertid 539in session 540.Fa sessid . 541It also sets the 542.Fa algorithm 543argument to the algorithm of the authorizer key. 544On failure, 545.Fn kn_get_authorizer 546returns 547.Dv NULL , 548and sets 549.Va keynote_errno 550to 551.Er ERROR_NOTFOUND . 552.Pp 553.Fn kn_get_licensees 554returns the licensee key(s) for assertion 555.Fa assertid 556in session 557.Fa sessid . 558The keys are returned in a linked list of 559.Fa struct keynote_keylist 560structures. 561On failure, 562.Fn kn_get_licensees 563returns 564.Dv NULL . 565and sets 566.Va keynote_errno 567to 568.Er ERROR_NOTFOUND . 569.Pp 570.Fn kn_query 571takes as arguments a list of action attributes in 572.Fa env , 573a list of return values in 574.Fa returnvalues 575(the number of returnvalues is indicated by 576.Fa numvalues ) , 577a number 578.Pf ( Fa numtrusted ) 579of locally-trusted assertions in 580.Fa trusted 581(the length of each assertion is given by the respective element of 582.Fa trustedlen ) , 583a number 584.Pf ( Fa numuntrusted ) 585of assertions that need to be cryptographically verified in 586.Fa untrusted 587(the length of each assertion is given by the respective element of 588.Fa untrustedlen ) , 589and a number 590.Pf ( Fa numauthorizers ) 591of action authorizers in 592.Fa authorizers . 593.Fa env 594is a linked list of 595.Fa struct environment 596structures. 597The 598.Fa env_name , 599.Fa env_value , 600and 601.Fa env_flags 602fields correspond to the 603.Fa name , 604.Fa value , 605and 606.Fa flags 607arguments to 608.Fn kn_add_assertion 609respectively. 610.Fa env_regex 611is not used. 612On success, this function returns an index in 613.Fa returnvalues 614indicating the returned value to the query. 615On failure, it returns \-1 and sets 616.Va keynote_errno 617to the same values as 618.Fn kn_do_query , 619or to 620.Er ERROR_MEMORY 621if a trusted or untrusted assertion could not be added to the session due 622to lack of memory resources. 623Syntax errors in assertions will not be reported by 624.Fn kn_query . 625.Pp 626.Fn kn_encode_base64 627converts the data of length 628.Fa srclen 629contained in 630.Fa src 631in Base64 encoding and stores them in 632.Fa dst 633which is of length 634.Fa dstlen . 635The actual length of the encoding stored in 636.Fa dst 637is returned. 638.Fa dst 639should be long enough to also contain the trailing 640string terminator. 641If 642.Fa dst 643is not long enough to contain the encoded data, this function returns 644\-1 and sets 645.Va keynote_errno 646to 647.Er ERROR_SYNTAX . 648.Pp 649.Fn kn_decode_base64 650decodes the Base64-encoded data stored in 651.Fa src 652and stores the result in 653.Fa dst , 654which is of length 655.Fa dstlen . 656The actual length of the decoded data is returned on success. 657On failure, this function returns \-1 and sets 658.Va keynote_errno 659to 660.Er ERROR_SYNTAX , 661denoting either an invalid Base64 encoding or insufficient space in 662.Fa dst . 663.Pp 664.Fn kn_encode_hex 665encodes in ASCII-hexadecimal format the data of length 666.Fa srclen 667contained in 668.Fa src . 669This function allocates a chunk of memory to store the result, which 670is returned in 671.Fa dst . 672Thus, this function should be used as follows: 673.Bd -literal 674 char *dst; 675 676 kn_encode_hex(src, &dst, srclen); 677.Ed 678.Pp 679The length of the allocated buffer will be (2 * srclen + 1). 680On success, this function returns 0. 681On failure, it returns \-1 and sets 682.Va keynote_errno 683to 684.Er ERROR_MEMORY 685if it failed to allocate enough memory, 686.Er ERROR_SYNTAX 687if 688.Fa dst 689was 690.Dv NULL . 691.Pp 692.Fn kn_decode_hex 693decodes the ASCII hex-encoded string in 694.Fa src 695and stores the result in a memory chunk allocated by the function. 696A pointer to that memory is stored in 697.Fa dst . 698The length of the allocated memory will be (strlen(src) / 2). 699On success, this function returns 0. 700On failure, it returns \-1 and sets 701.Va keynote_errno 702to 703.Er ERROR_MEMORY 704if it could not allocate enough memory, or 705.Er ERROR_SYNTAX 706if 707.Fa dst 708was 709.Dv NULL , 710or the length of 711.Fa src 712is not even. 713.Pp 714.Fn kn_encode_key 715ASCII-encodes a cryptographic key. 716The binary representation of the key is contained in 717.Fa dc . 718The field 719.Fa dec_key 720in that structure is a pointer to some cryptographic algorithm 721dependent information describing the key. 722In this implementation, this pointer should be a 723.Fa DSA * 724or 725.Fa RSA * 726for DSA or RSA keys respectively, as used in the SSL library, or a 727.Fa keynote_binary * 728for cryptographic keys whose algorithm 729.Nm 730does not know about but the application wishes to include in the 731action authorizers (and thus need to be canonicalized). 732The field 733.Fa dec_algorithm 734describes the cryptographic algorithm, and may be one of 735.Dv KEYNOTE_ALGORITHM_DSA , 736.Dv KEYNOTE_ALGORITHM_RSA , 737or 738.Dv KEYNOTE_ALGORITHM_BINARY 739in this implementation. 740.Pp 741.Fa iencoding 742describes how the key should be binary-encoded. 743This implementation supports 744.Dv INTERNAL_ENC_PKCS1 745for RSA keys, 746.Dv INTERNAL_ENC_ASN1 747for DSA keys, and 748.Dv INTERNAL_ENC_NONE 749for BINARY keys. 750.Fa encoding 751describes what ASCII encoding should be applied to the key. 752Valid values are 753.Dv ENCODING_HEX 754and 755.Dv ENCODING_BASE64 , 756for hexadecimal and Base64 encoding respectively. 757.Fa keytype 758is one of 759.Dv KEYNOTE_PUBLIC_KEY 760or 761.Dv KEYNOTE_PRIVATE_KEY 762to indicate whether the key is public or private. 763Private keys have the string 764.Dv KEYNOTE_PRIVATE_KEY_PREFIX 765(defined in keynote.h) prefixed to the algorithm name. 766On success, this function returns a string containing the encoded key. 767On failure, it returns 768.Dv NULL 769and sets 770.Va keynote_errno 771to 772.Er ERROR_NOTFOUND 773if the 774.Fa dc 775argument was invalid, 776.Er ERROR_MEMORY 777if it failed to allocate the necessary memory, or 778.Er ERROR_SYNTAX 779if the key to be converted was invalid. 780.Pp 781.Fn kn_decode_key 782decodes the ASCII-encoded string contained in 783.Fa key . 784The result is placed in 785.Fa dc , 786with 787.Fa dec_algorithm 788describing the algorithm (see 789.Fn kn_encode_key ) , 790and 791.Fa dec_key 792pointing to an algorithm-dependent structure. 793In this implementation, this is an SSLeay/OpenSSL-defined 794.Fa DSA * 795for DSA keys, 796.Fa RSA * 797for RSA and X.509-based keys, and a 798.Fa keynote_binary * 799for BINARY keys. 800.Fa keytype 801takes the values 802.Dv KEYNOTE_PUBLIC_KEY 803or 804.Dv KEYNOTE_PRIVATE_KEY 805to specify a public or private key, where applicable. 806On success, this function returns 0. 807On failure, it returns \-1 and sets 808.Va keynote_errno 809to 810.Er ERROR_MEMORY 811if necessary memory could not be allocated, or 812.Er ERROR_SYNTAX 813if the key or the ASCII encoding was malformed. 814.Pp 815.Fn kn_sign_assertion 816produces the cryptographic signature for the assertion of length 817.Fa len 818stored in 819.Fa assertion , 820using the ASCII-encoded cryptographic key contained in 821.Fa key . 822The type of signature to be produced is described by the string 823.Fa algorithm . 824Possible values for this string are 825.Dv SIG_RSA_SHA1_PKCS1_HEX , 826.Dv SIG_RSA_SHA1_PKCS1_BASE64 , 827.Dv SIG_RSA_MD5_HEX 828and 829.Dv SIG_RSA_MD5_HEX 830for RSA keys, 831.Dv SIG_DSA_SHA1_HEX 832and 833.Dv SIG_DSA_SHA1_BASE64 834for DSA keys, 835.Dv SIG_X509_SHA1_HEX 836and 837.Dv SIG_X509_SHA1_BASE64 838for X.509-based keys. 839No other cryptographic signatures are currently 840supported by this implementation. 841If 842.Fa vflag 843is set to 1, then the generated signature will also be verified. 844On success, this function returns a string containing the ASCII-encoded 845signature, without modifying the 846.Fa assertion . 847On failure, it returns 848.Dv NULL 849and sets 850.Va keynote_errno 851to 852.Er ERROR_NOTFOUND 853if one of the arguments was 854.Dv NULL , 855.Er ERROR_MEMORY 856if necessary memory could not be allocated, or 857.Er ERROR_SYNTAX 858if the 859.Fa algorithm , 860the 861.Fa key , 862or the 863.Fa assertion 864(if signature verification was requested) was invalid. 865.Pp 866.Fn kn_verify_assertion 867verifies the cryptographic signature on the assertion of length 868.Fa len 869contained in string 870.Fa assertion . 871On success, this function returns 872.Dv SIGRESULT_TRUE 873if the signature could be verified, or 874.Dv SIGRESULT_FALSE 875otherwise. 876On failure, this function returns \-1 and sets 877.Va keynote_errno 878to 879.Er ERROR_MEMORY 880if necessary memory could not be allocated, or 881.Er ERROR_SYNTAX 882if the assertion contained a syntactic error, or the cryptographic 883algorithm was not supported. 884.Pp 885.Fn kn_free_key 886frees a cryptographic key. 887.Pp 888.Fn kn_get_string 889parses the argument, treating it as a 890.Xr keynote 4 891(quoted) string. 892This is useful for parsing key files. 893On success, this function returns a pointer to the parsing result. 894The result is dynamically allocated and should be freed after use. 895On failure, 896.Dv NULL 897is returned. 898.Sh FILES 899.Bl -tag -width libkeynote.a -compact 900.It Pa keynote.h 901.It Pa libkeynote.a 902.El 903.Sh DIAGNOSTICS 904The return values of all the functions have been given along with the 905function description above. 906.Sh SEE ALSO 907.Xr keynote 1 , 908.Xr keynote 4 , 909.Xr keynote 5 910.Rs 911.%A M. Blaze 912.%A J. Feigenbaum 913.%A J. Lacy 914.%D 1996 915.%J IEEE Symposium on Security and Privacy 916.%T Decentralized Trust Management 917.Re 918.Rs 919.%A M. Blaze 920.%A J. Feigenbaum 921.%A M. Strauss 922.%D 1998 923.%J Financial Crypto Conference 924.%T Compliance-Checking in the PolicyMaker Trust Management System 925.Re 926.Sh STANDARDS 927.Rs 928.%A M. Blaze 929.%A J. Feigenbaum 930.%A J. Ioannidis 931.%A A. Keromytis 932.%D September 1999 933.%R RFC 2704 934.%T The KeyNote Trust-Management System Version 2 935.Re 936.Sh AUTHORS 937.An Angelos D. Keromytis Aq Mt angelos@cs.columbia.edu 938.Sh WEB PAGE 939.Lk http://www1.cs.columbia.edu/~angelos/keynote.html 940