1/* 2 * Copyright (c) 2008 Kungliga Tekniska Högskolan 3 * (Royal Institute of Technology, Stockholm, Sweden). 4 * All rights reserved. 5 * 6 * Portions Copyright (c) 2009 - 2010 Apple Inc. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * 3. Neither the name of KTH nor the names of its contributors may be 20 * used to endorse or promote products derived from this software without 21 * specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY 24 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE 27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36#include "config.h" 37 38#include <stdio.h> 39#include <stdlib.h> 40#include <string.h> 41#include <errno.h> 42 43#include <krb5-types.h> 44 45#include <wind.h> 46#include <roken.h> 47#include <base64.h> 48 49#include <heimbase.h> 50 51#include "heimscram.h" 52 53#include <ntlm_err.h> 54#include "crypto-headers.h" 55 56#ifndef __APPLE_TARGET_EMBEDDED__ 57#include <CommonCrypto/CommonKeyDerivation.h> 58#endif 59 60 61struct heim_scram_pair { 62 char type; 63 heim_scram_data data; 64}; 65 66struct heim_scram_pairs { 67 int flags; 68#define SCRAM_PAIR_ALLOCATED 1 69#define SCRAM_ARRAY_ALLOCATED 2 70#define SCRAM_BINDINGS_YES 4 71#define SCRAM_BINDINGS_NO 8 72 struct heim_scram_pair *val; 73 size_t len; 74}; 75 76typedef struct heim_scram_pairs heim_scram_pairs; 77 78struct heim_scram { 79 struct heim_scram_method_desc *method; 80 enum { CLIENT, SERVER } type; 81 heim_scram_data client1; 82 heim_scram_data server1; 83 /* generated */ 84 heim_scram_data nonce; 85 86 /* server */ 87 struct heim_scram_server *server; 88 void *ctx; 89 90 heim_scram_data user; 91 92 /* output */ 93 heim_scram_data ClientProof; 94 heim_scram_data ServerSignature; 95 heim_scram_data SessionKey; 96}; 97 98#include "heimscram-protos.h" 99 100int 101_heim_scram_parse(heim_scram_data *data, heim_scram_pairs **pd); 102 103int 104_heim_scram_unparse ( 105 heim_scram_pairs */*d*/, 106 heim_scram_data */*out*/); 107 108void 109_heim_scram_pairs_free (heim_scram_pairs */*d*/); 110