diff --git a/APDU/APDU.h b/APDU/APDU.h index 0d2c0db..b37b3e2 100644 --- a/APDU/APDU.h +++ b/APDU/APDU.h @@ -3,7 +3,6 @@ // APDU // // Created by Benjamin P Toews on 2/7/17. -// Copyright © 2017 GitHub. All rights reserved. // #import @@ -15,5 +14,3 @@ FOUNDATION_EXPORT double APDUVersionNumber; FOUNDATION_EXPORT const unsigned char APDUVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import - - diff --git a/APDU/AuthenticationRequest.swift b/APDU/AuthenticationRequest.swift index d78f179..a68d423 100644 --- a/APDU/AuthenticationRequest.swift +++ b/APDU/AuthenticationRequest.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 9/14/16. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation diff --git a/APDU/AuthenticationResponse.swift b/APDU/AuthenticationResponse.swift index 9a38717..1b54736 100644 --- a/APDU/AuthenticationResponse.swift +++ b/APDU/AuthenticationResponse.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 9/14/16. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation @@ -11,7 +10,7 @@ import Foundation public struct AuthenticationResponse: RawConvertible { let body: Data let trailer: ResponseStatus - + public var userPresence: UInt8 { return body[0] } @@ -20,7 +19,7 @@ public struct AuthenticationResponse: RawConvertible { let lowerBound = MemoryLayout.size let upperBound = lowerBound + MemoryLayout.size let data = body.subdata(in: lowerBound..) -> UInt32 in return ptr.pointee.bigEndian } @@ -37,7 +36,7 @@ public struct AuthenticationResponse: RawConvertible { writer.write(userPresence) writer.write(counter) writer.writeData(signature) - + body = writer.buffer trailer = .NoError } @@ -48,13 +47,13 @@ extension AuthenticationResponse: Response { self.body = body self.trailer = trailer } - + func validateBody() throws { // TODO: minimum signature size? if body.count < MemoryLayout.size + MemoryLayout.size + 1 { throw ResponseError.BadSize } - + if trailer != .NoError { throw ResponseError.BadStatus } diff --git a/APDU/Command.swift b/APDU/Command.swift index 40f0e0e..e808b35 100644 --- a/APDU/Command.swift +++ b/APDU/Command.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 2/7/17. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation @@ -18,9 +17,9 @@ public protocol Command { var header: CommandHeader { get } var body: Data { get } var trailer: CommandTrailer { get } - + init(header: CommandHeader, body: Data, trailer: CommandTrailer) - + func validateBody() throws } @@ -31,16 +30,16 @@ extension Command { writer.writeData(header.raw) writer.writeData(body) writer.writeData(trailer.raw) - + return writer.buffer } - + public init(raw: Data) throws { let reader = DataReader(data: raw) let header: CommandHeader let body: Data let trailer: CommandTrailer - + do { header = try CommandHeader(reader: reader) body = try reader.readData(header.dataLength) @@ -48,7 +47,7 @@ extension Command { } catch DataReaderError.End { throw ResponseStatus.WrongLength } - + self.init(header: header, body: body, trailer: trailer) try validateBody() diff --git a/APDU/CommandHeader.swift b/APDU/CommandHeader.swift index c563544..fa899cd 100644 --- a/APDU/CommandHeader.swift +++ b/APDU/CommandHeader.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 9/11/16. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation @@ -64,7 +63,7 @@ public struct CommandHeader: RawConvertible, MessagePart { throw ResponseStatus.WrongLength } } - + init(cla: CommandClass = .Reserved, ins: CommandCode, p1: UInt8 = 0x00, p2: UInt8 = 0x00, dataLength: Int) { self.cla = cla self.ins = ins diff --git a/APDU/CommandTrailer.swift b/APDU/CommandTrailer.swift index 8b77555..0332b84 100644 --- a/APDU/CommandTrailer.swift +++ b/APDU/CommandTrailer.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/25/17. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation @@ -54,7 +53,7 @@ public struct CommandTrailer: RawConvertible, MessagePart { throw ResponseStatus.WrongLength } } - + init(noBody: Bool, maxResponse: Int = MaxResponseSize) { self.noBody = noBody self.maxResponse = maxResponse diff --git a/APDU/Constants.swift b/APDU/Constants.swift index 9197bc8..f6e68fc 100644 --- a/APDU/Constants.swift +++ b/APDU/Constants.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 2/7/17. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation @@ -31,7 +30,7 @@ public enum CommandCode: UInt8 { public enum Control: UInt8 { case EnforceUserPresenceAndSign = 0x03 case CheckOnly = 0x07 - + // Used internally. case Invalid = 0xFF } @@ -39,7 +38,7 @@ public enum Control: UInt8 { // ISO7816-4 public enum ResponseStatus: UInt16, EndianEnumProtocol, Error { public typealias RawValue = UInt16 - + case NoError = 0x9000 case WrongData = 0x6A80 case ConditionsNotSatisfied = 0x6985 diff --git a/APDU/Data/DataReader.swift b/APDU/Data/DataReader.swift index f09e150..307a239 100644 --- a/APDU/Data/DataReader.swift +++ b/APDU/Data/DataReader.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 9/11/16. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation diff --git a/APDU/Data/DataWriter.swift b/APDU/Data/DataWriter.swift index b32fd0e..14a33a6 100644 --- a/APDU/Data/DataWriter.swift +++ b/APDU/Data/DataWriter.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 9/12/16. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation diff --git a/APDU/Data/Endian.swift b/APDU/Data/Endian.swift index 0f00b20..18b3f1f 100644 --- a/APDU/Data/Endian.swift +++ b/APDU/Data/Endian.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 9/12/16. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation diff --git a/APDU/ErrorResponse.swift b/APDU/ErrorResponse.swift index f223e15..9449f77 100644 --- a/APDU/ErrorResponse.swift +++ b/APDU/ErrorResponse.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/26/17. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation @@ -23,7 +22,7 @@ extension ErrorResponse: Response { self.body = body self.trailer = trailer } - + func validateBody() throws { if body.count != 0 { throw ResponseError.BadSize diff --git a/APDU/MessagePart.swift b/APDU/MessagePart.swift index a89384d..e86ddc2 100644 --- a/APDU/MessagePart.swift +++ b/APDU/MessagePart.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 2/7/17. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation diff --git a/APDU/RawConvertible.swift b/APDU/RawConvertible.swift index 2ef63b2..7c30718 100644 --- a/APDU/RawConvertible.swift +++ b/APDU/RawConvertible.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 2/7/17. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation diff --git a/APDU/RegisterRequest.swift b/APDU/RegisterRequest.swift index ee5afd3..e58d688 100644 --- a/APDU/RegisterRequest.swift +++ b/APDU/RegisterRequest.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 9/10/16. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation @@ -12,7 +11,7 @@ public struct RegisterRequest: RawConvertible { public let header: CommandHeader public let body: Data public let trailer: CommandTrailer - + public var challengeParameter: Data { let lowerBound = 0 let upperBound = lowerBound + U2F_CHAL_SIZE @@ -29,7 +28,7 @@ public struct RegisterRequest: RawConvertible { let writer = DataWriter() writer.writeData(challengeParameter) writer.writeData(applicationParameter) - + self.body = writer.buffer self.header = CommandHeader(ins: .Register, dataLength: body.count) self.trailer = CommandTrailer(noBody: false) @@ -42,7 +41,7 @@ extension RegisterRequest: Command { self.body = body self.trailer = trailer } - + public func validateBody() throws { if body.count != U2F_CHAL_SIZE + U2F_APPID_SIZE { throw ResponseStatus.WrongLength diff --git a/APDU/RegisterResponse.swift b/APDU/RegisterResponse.swift index a2f3ebd..aeff541 100644 --- a/APDU/RegisterResponse.swift +++ b/APDU/RegisterResponse.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 9/11/16. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation @@ -16,11 +15,11 @@ public struct RegisterResponse: RawConvertible { var reserved: UInt8 { return body.subdata(in: reservedRange)[0] } - + public var publicKey: Data { return body.subdata(in: publicKeyRange) } - + var keyHandleLength: Int { return Int(body.subdata(in: keyHandleLengthRange)[0]) } @@ -28,7 +27,7 @@ public struct RegisterResponse: RawConvertible { public var keyHandle: Data { return body.subdata(in: keyHandleRange) } - + public var certificate: Data { return body.subdata(in: certificateRange) } @@ -42,13 +41,13 @@ public struct RegisterResponse: RawConvertible { let upperBound = MemoryLayout.size return lowerBound.. { let lowerBound = reservedRange.upperBound let upperBound = lowerBound + U2F_EC_POINT_SIZE return lowerBound.. { let lowerBound = publicKeyRange.upperBound let upperBound = lowerBound + MemoryLayout.size @@ -60,7 +59,7 @@ public struct RegisterResponse: RawConvertible { let upperBound = lowerBound + keyHandleLength return lowerBound.. = keyHandleRange.upperBound.. { let lowerBound = keyHandleRange.upperBound let upperBound = lowerBound + certificateSize return lowerBound.. { let lowerBound = certificateRange.upperBound let upperBound = body.count return lowerBound...size + U2F_EC_POINT_SIZE + MemoryLayout.size @@ -118,12 +117,12 @@ extension RegisterResponse: Response { if body.count < min { throw ResponseError.BadSize } - + // Check that cert is parsable. if certificateSize == 0 { throw ResponseError.BadCertificate } - + // Check that we at least have one byte of signature. // TODO: minimum signature size? min += certificateSize + 1 @@ -134,7 +133,7 @@ extension RegisterResponse: Response { if reserved != 0x05 { throw ResponseError.BadData } - + if trailer != .NoError { throw ResponseError.BadStatus } diff --git a/APDU/Response.swift b/APDU/Response.swift index e1436a6..94f9dad 100644 --- a/APDU/Response.swift +++ b/APDU/Response.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 2/7/17. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation @@ -18,9 +17,9 @@ enum ResponseError: Error { protocol Response { var body: Data { get } var trailer: ResponseStatus { get } - + init(body: Data, trailer: ResponseStatus) - + func validateBody() throws } @@ -30,10 +29,10 @@ extension Response { let writer = DataWriter() writer.writeData(body) writer.write(trailer) - + return writer.buffer } - + public init(raw: Data) throws { let reader = DataReader(data: raw) let body = try reader.readData(reader.remaining - 2) @@ -43,7 +42,7 @@ extension Response { try validateBody() } - + // For testing with libu2f-host public init(raw: Data, bodyOnly: Bool) throws { if bodyOnly { diff --git a/APDU/VersionRequest.swift b/APDU/VersionRequest.swift index ae5f014..8969e82 100644 --- a/APDU/VersionRequest.swift +++ b/APDU/VersionRequest.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/25/17. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation @@ -12,7 +11,7 @@ public struct VersionRequest: RawConvertible { public let header: CommandHeader public let body: Data public let trailer: CommandTrailer - + init() { self.header = CommandHeader(ins: .Version, dataLength: 0) self.body = Data() @@ -26,7 +25,7 @@ extension VersionRequest: Command { self.body = body self.trailer = trailer } - + public func validateBody() throws { if body.count > 0 { throw ResponseStatus.WrongLength diff --git a/APDU/VersionResponse.swift b/APDU/VersionResponse.swift index 6a01b21..4cd8129 100644 --- a/APDU/VersionResponse.swift +++ b/APDU/VersionResponse.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/25/17. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation @@ -11,7 +10,7 @@ import Foundation public struct VersionResponse: RawConvertible { let body: Data let trailer: ResponseStatus - + public var version: String { return String(data: body, encoding: .utf8) ?? "" } @@ -27,12 +26,12 @@ extension VersionResponse: Response { self.body = body self.trailer = trailer } - + func validateBody() throws { if version.lengthOfBytes(using: .utf8) < 1 { throw ResponseError.BadSize } - + if trailer != .NoError { throw ResponseError.BadStatus } diff --git a/APDUTests/AuthenticationRequestTests.swift b/APDUTests/AuthenticationRequestTests.swift index 322dbb5..b9d6441 100644 --- a/APDUTests/AuthenticationRequestTests.swift +++ b/APDUTests/AuthenticationRequestTests.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 2/6/17. -// Copyright © 2017 GitHub. All rights reserved. // import XCTest @@ -11,7 +10,7 @@ class AuthenticationRequestTests: XCTestCase { func testChromeRequest() throws { let r = Data(base64Encoded: "AAIDAAAAgeOwxEKY/BwUmvv0yJlvuSQnrkHkZJuTTKSVmRt4UrhVcGF9/tBlhjr0fBVVbJF5iICCjMQH/fcK6FARVpRloHVAIA5xiih5UyR97Gx8DMpSZgno9djTV85XM+VQfZNgADuFrTX978Gq3C8F6BfBLgD042ioARsymZUhkDxd3i3nsQAA")! let c = try AuthenticationRequest(raw: r) - + XCTAssertEqual(c.header.cla, CommandClass.Reserved) XCTAssertEqual(c.header.ins, CommandCode.Authenticate) XCTAssertEqual(c.header.p1, Control.EnforceUserPresenceAndSign.rawValue) @@ -19,13 +18,13 @@ class AuthenticationRequestTests: XCTestCase { XCTAssertEqual(c.trailer.maxResponse, MaxResponseSize) XCTAssertEqual(c.raw, r) } - + func testRequest() throws { let c = Data(repeating: 0xAA, count: 32) let a = Data(repeating: 0xBB, count: 32) let k = Data(repeating: 0xCC, count: 16) let cmd = AuthenticationRequest(challengeParameter: c, applicationParameter: a, keyHandle: k, control: .CheckOnly) - + XCTAssertEqual(cmd.header.cla, CommandClass.Reserved) XCTAssertEqual(cmd.header.ins, CommandCode.Authenticate) XCTAssertEqual(cmd.control, Control.CheckOnly) @@ -49,7 +48,7 @@ class AuthenticationRequestTests: XCTestCase { 0x00, 0x00 ])) - + let cmd2 = try AuthenticationRequest(raw: cmd.raw) XCTAssertEqual(cmd.header.cla, cmd2.header.cla) XCTAssertEqual(cmd.header.ins, cmd2.header.ins) diff --git a/APDUTests/CommandHeaderTests.swift b/APDUTests/CommandHeaderTests.swift index 02a84ee..1f7e9ee 100644 --- a/APDUTests/CommandHeaderTests.swift +++ b/APDUTests/CommandHeaderTests.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 9/11/16. -// Copyright © 2017 GitHub. All rights reserved. // import XCTest diff --git a/APDUTests/CommandTrailerTests.swift b/APDUTests/CommandTrailerTests.swift index 24deafb..2df4c5f 100644 --- a/APDUTests/CommandTrailerTests.swift +++ b/APDUTests/CommandTrailerTests.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/25/17. -// Copyright © 2017 GitHub. All rights reserved. // import XCTest diff --git a/APDUTests/DataTests/DataReaderTests.swift b/APDUTests/DataTests/DataReaderTests.swift index 10d710c..f19b511 100644 --- a/APDUTests/DataTests/DataReaderTests.swift +++ b/APDUTests/DataTests/DataReaderTests.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 9/11/16. -// Copyright © 2017 GitHub. All rights reserved. // import XCTest diff --git a/APDUTests/DataTests/DataWriterTests.swift b/APDUTests/DataTests/DataWriterTests.swift index ed1b0be..42d11e4 100644 --- a/APDUTests/DataTests/DataWriterTests.swift +++ b/APDUTests/DataTests/DataWriterTests.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 9/12/16. -// Copyright © 2017 GitHub. All rights reserved. // import XCTest diff --git a/APDUTests/RegisterRequestTests.swift b/APDUTests/RegisterRequestTests.swift index 08037b5..57525fd 100644 --- a/APDUTests/RegisterRequestTests.swift +++ b/APDUTests/RegisterRequestTests.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 2/6/17. -// Copyright © 2017 GitHub. All rights reserved. // import XCTest @@ -13,7 +12,7 @@ class RegisterRequestTests: XCTestCase { func testChromeRequest() throws { let r = Data(base64Encoded: "AAEDAAAAQEr8hj61EL83BjxGaqSnMUyWyXeBIAhGhQ2zbkFcgOzbcGF9/tBlhjr0fBVVbJF5iICCjMQH/fcK6FARVpRloHUAAA==")! let c = try RegisterRequest(raw: r) - + XCTAssertEqual(c.header.cla, CommandClass.Reserved) XCTAssertEqual(c.header.ins, CommandCode.Register) XCTAssertEqual(c.header.p1, Control.EnforceUserPresenceAndSign.rawValue) @@ -21,7 +20,7 @@ class RegisterRequestTests: XCTestCase { XCTAssertEqual(c.trailer.maxResponse, MaxResponseSize) XCTAssertEqual(c.raw, r) } - + func testRequest() throws { let c = Data(repeating: 0xAA, count: 32) let a = Data(repeating: 0xBB, count: 32) @@ -47,7 +46,7 @@ class RegisterRequestTests: XCTestCase { 0x00, 0x00 ])) - + let cmd2 = try RegisterRequest(raw: cmd.raw) XCTAssertEqual(cmd.header.cla, cmd2.header.cla) XCTAssertEqual(cmd.header.ins, cmd2.header.ins) diff --git a/APDUTests/ResponseTests.swift b/APDUTests/ResponseTests.swift index 23c44c8..cd3d7b3 100644 --- a/APDUTests/ResponseTests.swift +++ b/APDUTests/ResponseTests.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 9/12/16. -// Copyright © 2017 GitHub. All rights reserved. // import XCTest diff --git a/APDUTests/TestUtil.swift b/APDUTests/TestUtil.swift index f6decb7..55b43d0 100644 --- a/APDUTests/TestUtil.swift +++ b/APDUTests/TestUtil.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 9/10/16. -// Copyright © 2017 GitHub. All rights reserved. // import XCTest diff --git a/APDUTests/VersionRequestTests.swift b/APDUTests/VersionRequestTests.swift index 9839086..e54fb12 100644 --- a/APDUTests/VersionRequestTests.swift +++ b/APDUTests/VersionRequestTests.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 2/6/17. -// Copyright © 2017 GitHub. All rights reserved. // import XCTest @@ -13,7 +12,7 @@ class VersionRequestTests: XCTestCase { func testChromeRequest() throws { let r = Data(base64Encoded: "AAMAAAAAAA==")! let c = try VersionRequest(raw: r) - + XCTAssertEqual(c.header.cla, CommandClass.Reserved) XCTAssertEqual(c.header.ins, CommandCode.Version) XCTAssertEqual(c.header.p1, 0x00) @@ -23,7 +22,7 @@ class VersionRequestTests: XCTestCase { XCTAssertEqual(c.trailer.maxResponse, MaxResponseSize) XCTAssertEqual(c.raw, r) } - + func testRequest() { let c = VersionRequest() diff --git a/SelfSignedCertificate/SelfSignedCertificate.h b/SelfSignedCertificate/SelfSignedCertificate.h index 7ae368a..a53f3d3 100644 --- a/SelfSignedCertificate/SelfSignedCertificate.h +++ b/SelfSignedCertificate/SelfSignedCertificate.h @@ -3,7 +3,6 @@ // SelfSignedCertificate // // Created by Benjamin P Toews on 2/7/17. -// Copyright © 2017 GitHub. All rights reserved. // #import @@ -15,5 +14,3 @@ FOUNDATION_EXPORT double SelfSignedCertificateVersionNumber; FOUNDATION_EXPORT const unsigned char SelfSignedCertificateVersionString[]; #import "public.h" - - diff --git a/SelfSignedCertificate/SelfSignedCertificate.m b/SelfSignedCertificate/SelfSignedCertificate.m index 275f45d..2bff37e 100644 --- a/SelfSignedCertificate/SelfSignedCertificate.m +++ b/SelfSignedCertificate/SelfSignedCertificate.m @@ -3,7 +3,6 @@ // SecurityKey // // Created by Benjamin P Toews on 8/19/16. -// Copyright © 2017 GitHub, inc. All rights reserved. // #import "private.h" @@ -53,7 +52,7 @@ + (NSData *)toDer { unsigned char *buf; X509 *x509; const unsigned char *crt_cpy = cert; - + x509 = d2i_X509(NULL, &crt_cpy, cert_len); if (x509 == NULL) { printf("failed to parse cert\n"); @@ -67,9 +66,9 @@ + (NSData *)toDer { X509_free(x509); return nil; } - + X509_free(x509); - + return [[NSData alloc] initWithBytes:buf length:len]; } @@ -81,33 +80,33 @@ + (NSData *)signData:(NSData *)msg { EC_KEY *ec; EVP_PKEY *pkey; const unsigned char *priv_cpy = priv; - + ec = d2i_ECPrivateKey(NULL, &priv_cpy, priv_len); if (ec == NULL) { printf("error importing private key\n"); return nil; } - + if (EC_KEY_check_key(ec) != 1) { printf("error checking key\n"); EC_KEY_free(ec); return nil; } - + pkey = EVP_PKEY_new(); if (pkey == NULL) { printf("failed to init pkey\n"); EC_KEY_free(ec); return nil; } - + if (EVP_PKEY_assign_EC_KEY(pkey, ec) != 1) { printf("failed to assing ec to pkey\n"); EC_KEY_free(ec); EVP_PKEY_free(pkey); return nil; } - + // `ec` memory is managed by `pkey` from here. if (EVP_SignInit(&ctx, EVP_sha256()) != 1) { @@ -121,7 +120,7 @@ + (NSData *)signData:(NSData *)msg { EVP_PKEY_free(pkey); return nil; } - + sig = (unsigned char *)malloc(EVP_PKEY_size(pkey)); if (sig == NULL) { printf("failed to malloc for sig\n"); diff --git a/SelfSignedCertificate/private.h b/SelfSignedCertificate/private.h index fa99f85..f028535 100644 --- a/SelfSignedCertificate/private.h +++ b/SelfSignedCertificate/private.h @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 2/7/17. -// Copyright © 2017 GitHub. All rights reserved. // #ifndef private_h diff --git a/SelfSignedCertificate/public.h b/SelfSignedCertificate/public.h index 33d02ba..40f7daf 100644 --- a/SelfSignedCertificate/public.h +++ b/SelfSignedCertificate/public.h @@ -3,7 +3,6 @@ // SelfSignedCertificate // // Created by Benjamin P Toews on 8/19/16. -// Copyright © 2017 GitHub, inc. All rights reserved. // #ifndef public_h diff --git a/SelfSignedCertificateTests/SelfSignedCertificateTests.swift b/SelfSignedCertificateTests/SelfSignedCertificateTests.swift index e213ac4..12dcd5b 100644 --- a/SelfSignedCertificateTests/SelfSignedCertificateTests.swift +++ b/SelfSignedCertificateTests/SelfSignedCertificateTests.swift @@ -3,7 +3,6 @@ // SelfSignedCertificateTests // // Created by Benjamin P Toews on 2/7/17. -// Copyright © 2017 GitHub. All rights reserved. // import XCTest @@ -12,12 +11,12 @@ import SelfSignedCertificate class SelfSignedCertificateTests: XCTestCase { func testParseX509() { guard var der = SelfSignedCertificate.toDer() else { XCTFail("Error DER formatting cert"); return } - + let crtLen = der.count var parsedLen = 0 - + der.append(Data(bytes: [0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF])) - + XCTAssert(SelfSignedCertificate.parseX509(der, consumed: &parsedLen), "Error parsing cert") XCTAssertEqual(crtLen, parsedLen) } diff --git a/SoftU2FDriver/SoftU2FDevice.cpp b/SoftU2FDriver/SoftU2FDevice.cpp index 7b92bde..88c9cce 100644 --- a/SoftU2FDriver/SoftU2FDevice.cpp +++ b/SoftU2FDriver/SoftU2FDevice.cpp @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/12/17. -// Copyright © 2017 GitHub. All rights reserved. // #include "SoftU2FDevice.hpp" diff --git a/SoftU2FDriver/SoftU2FDevice.hpp b/SoftU2FDriver/SoftU2FDevice.hpp index 6309578..4c11381 100644 --- a/SoftU2FDriver/SoftU2FDevice.hpp +++ b/SoftU2FDriver/SoftU2FDevice.hpp @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/12/17. -// Copyright © 2017 GitHub. All rights reserved. // #ifndef SoftU2FDevice_hpp diff --git a/SoftU2FDriver/SoftU2FDriver.cpp b/SoftU2FDriver/SoftU2FDriver.cpp index 891f937..01761c8 100644 --- a/SoftU2FDriver/SoftU2FDriver.cpp +++ b/SoftU2FDriver/SoftU2FDriver.cpp @@ -3,7 +3,7 @@ // SoftU2F // // Created by Benjamin P Toews on 1/12/17. -// Copyright © 2017 GitHub. All rights reserved. +// #include #include "SoftU2FDriver.hpp" diff --git a/SoftU2FDriver/SoftU2FDriver.hpp b/SoftU2FDriver/SoftU2FDriver.hpp index 8572467..641e577 100644 --- a/SoftU2FDriver/SoftU2FDriver.hpp +++ b/SoftU2FDriver/SoftU2FDriver.hpp @@ -3,7 +3,7 @@ // SoftU2F // // Created by Benjamin P Toews on 1/12/17. -// Copyright © 2017 GitHub. All rights reserved. +// #ifndef SoftU2FDriver_hpp #define SoftU2FDriver_hpp diff --git a/SoftU2FDriver/SoftU2FUserClient.cpp b/SoftU2FDriver/SoftU2FUserClient.cpp index 380d267..f1c6464 100644 --- a/SoftU2FDriver/SoftU2FUserClient.cpp +++ b/SoftU2FDriver/SoftU2FUserClient.cpp @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/12/17. -// Copyright © 2017 GitHub. All rights reserved. // #include "SoftU2FUserClient.hpp" diff --git a/SoftU2FDriver/SoftU2FUserClient.hpp b/SoftU2FDriver/SoftU2FUserClient.hpp index 90ef47d..b79ed12 100644 --- a/SoftU2FDriver/SoftU2FUserClient.hpp +++ b/SoftU2FDriver/SoftU2FUserClient.hpp @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/12/17. -// Copyright © 2017 GitHub. All rights reserved. // #ifndef SoftU2FUserClient_hpp diff --git a/SoftU2FDriver/UserKernelShared.h b/SoftU2FDriver/UserKernelShared.h index b0b0315..5cded7f 100644 --- a/SoftU2FDriver/UserKernelShared.h +++ b/SoftU2FDriver/UserKernelShared.h @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/12/17. -// Copyright © 2017 GitHub. All rights reserved. // #ifndef UserKernelShared_h diff --git a/SoftU2FDriverLib/internal.h b/SoftU2FDriverLib/internal.h index 26c23d0..1447541 100644 --- a/SoftU2FDriverLib/internal.h +++ b/SoftU2FDriverLib/internal.h @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/25/17. -// Copyright © 2017 GitHub. All rights reserved. // #ifndef internal_h diff --git a/SoftU2FDriverLib/softu2f.c b/SoftU2FDriverLib/softu2f.c index c428670..31d8b1f 100644 --- a/SoftU2FDriverLib/softu2f.c +++ b/SoftU2FDriverLib/softu2f.c @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/12/17. -// Copyright © 2017 GitHub. All rights reserved. // #include "softu2f.h" diff --git a/SoftU2FDriverLib/softu2f.h b/SoftU2FDriverLib/softu2f.h index 8f8bc7c..9c7c36b 100644 --- a/SoftU2FDriverLib/softu2f.h +++ b/SoftU2FDriverLib/softu2f.h @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/12/17. -// Copyright © 2017 GitHub. All rights reserved. // #ifndef SoftU2FClientInterface_h diff --git a/SoftU2FTool/AppDelegate.swift b/SoftU2FTool/AppDelegate.swift index 506e32a..84672f9 100644 --- a/SoftU2FTool/AppDelegate.swift +++ b/SoftU2FTool/AppDelegate.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/24/17. -// Copyright © 2017 GitHub. All rights reserved. // import Cocoa @@ -22,7 +21,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { print("Error stopping authenticator") } } - + func applicationDidBecomeActive(_ notification: Notification) { // Chrome gives ignores our U2F responses if it isn't active when we send them. // This hack should give focus back to Chrome immediately after the user interacts diff --git a/SoftU2FTool/KeyPair.swift b/SoftU2FTool/KeyPair.swift index 0acd199..54b4380 100644 --- a/SoftU2FTool/KeyPair.swift +++ b/SoftU2FTool/KeyPair.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 2/2/17. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation diff --git a/SoftU2FTool/Keychain.swift b/SoftU2FTool/Keychain.swift index cf6cbc6..f5eab50 100644 --- a/SoftU2FTool/Keychain.swift +++ b/SoftU2FTool/Keychain.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 2/2/17. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation diff --git a/SoftU2FTool/KnownFacets.swift b/SoftU2FTool/KnownFacets.swift index e987e94..f748af0 100644 --- a/SoftU2FTool/KnownFacets.swift +++ b/SoftU2FTool/KnownFacets.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/27/17. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation diff --git a/SoftU2FTool/SHA256.swift b/SoftU2FTool/SHA256.swift index a3f6058..d1ba1b4 100644 --- a/SoftU2FTool/SHA256.swift +++ b/SoftU2FTool/SHA256.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 9/10/16. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation diff --git a/SoftU2FTool/U2FAuthenticator.swift b/SoftU2FTool/U2FAuthenticator.swift index cc7b2cc..9a5eace 100644 --- a/SoftU2FTool/U2FAuthenticator.swift +++ b/SoftU2FTool/U2FAuthenticator.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/25/17. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation @@ -44,7 +43,7 @@ class U2FAuthenticator { func installMsgHandler() { u2fhid.handle(.Msg) { (_ msg: softu2f_hid_message) -> Bool in let data = msg.data.takeUnretainedValue() as Data - + do { let ins = try APDU.commandType(raw: data) @@ -63,14 +62,14 @@ class U2FAuthenticator { } catch { self.sendError(status: .OtherError, cid: msg.cid) } - + return true } } func handleRegisterRequest(_ raw: Data, cid: UInt32) throws { let req = try APDU.RegisterRequest(raw: raw) - + let facet = KnownFacets[req.applicationParameter] let notification = UserPresence.Notification.Register(facet: facet) @@ -94,7 +93,7 @@ class U2FAuthenticator { let payloadSize = 1 + req.applicationParameter.count + req.challengeParameter.count + reg.keyHandle.count + publicKey.count var sigPayload = Data(capacity: payloadSize) - + sigPayload.append(UInt8(0x00)) // reserved sigPayload.append(req.applicationParameter) sigPayload.append(req.challengeParameter) @@ -115,7 +114,7 @@ class U2FAuthenticator { func handleAuthenticationRequest(_ raw: Data, cid: UInt32) throws { let req = try APDU.AuthenticationRequest(raw: raw) - + guard let reg = U2FRegistration(keyHandle: req.keyHandle, applicationParameter: req.applicationParameter) else { sendError(status: .WrongData, cid: cid) return @@ -138,7 +137,7 @@ class U2FAuthenticator { let counter = reg.counter var ctrBigEndian = counter.bigEndian - + let payloadSize = req.applicationParameter.count + 1 + MemoryLayout.size + req.challengeParameter.count var sigPayload = Data(capacity: payloadSize) diff --git a/SoftU2FTool/U2FHID.swift b/SoftU2FTool/U2FHID.swift index 363f4de..2127cb5 100644 --- a/SoftU2FTool/U2FHID.swift +++ b/SoftU2FTool/U2FHID.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/25/17. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation @@ -58,7 +57,7 @@ class U2FHID { msg.cmd = MessageType.Msg.rawValue msg.bcnt = UInt16(data.count) msg.cid = cid - + let cfd = data as CFData msg.data = Unmanaged.passUnretained(cfd) diff --git a/SoftU2FTool/U2FRegistration.swift b/SoftU2FTool/U2FRegistration.swift index 820dab0..94872f8 100644 --- a/SoftU2FTool/U2FRegistration.swift +++ b/SoftU2FTool/U2FRegistration.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/30/17. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation @@ -50,14 +49,14 @@ class U2FRegistration { // Read our application parameter from the keychain and make sure it matches. guard let appTag = keyPair.applicationTag else { return nil } - + let counterSize = MemoryLayout.size let appTagSize = Int(U2F_APPID_SIZE) - + if appTag.count != counterSize + appTagSize { return nil } - + counter = appTag.withUnsafeBytes { (ptr:UnsafePointer) -> UInt32 in return ptr.pointee.bigEndian } @@ -93,7 +92,7 @@ class U2FRegistration { let appTagSize = Int(U2F_APPID_SIZE) var data = Data(capacity: counterSize + appTagSize) var ctrBigEndian = counter.bigEndian - + data.append(Data(bytes: &ctrBigEndian, count: counterSize)) data.append(applicationParameter) diff --git a/SoftU2FTool/UserPresence.swift b/SoftU2FTool/UserPresence.swift index 1911104..f16d055 100644 --- a/SoftU2FTool/UserPresence.swift +++ b/SoftU2FTool/UserPresence.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/27/17. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation @@ -44,7 +43,7 @@ class UserPresence: NSObject { } else { // Fail any outstanding test. current?.complete(false) - + // Backup previous delegate to restore on completion. let delegateWas = NSUserNotificationCenter.default.delegate @@ -82,7 +81,7 @@ class UserPresence: NSObject { func test(_ type: Notification) { if #available(OSX 10.12.2, *) { let ctx = LAContext() - + if ctx.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) { ctx.localizedCancelTitle = "Reject" ctx.localizedFallbackTitle = "Skip TouchID" @@ -94,13 +93,13 @@ class UserPresence: NSObject { case let .Authenticate(facet): prompt = "authenticate with " + (facet ?? "site") } - + ctx.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: prompt) { (success, err) in guard let lerr = err as? LAError else { self.complete(success) return } - + switch lerr.code { case .userFallback, .touchIDNotAvailable, .touchIDNotEnrolled: self.sendNotification(type) diff --git a/SoftU2FTool/Utils.swift b/SoftU2FTool/Utils.swift index a6017ef..ff0cb45 100644 --- a/SoftU2FTool/Utils.swift +++ b/SoftU2FTool/Utils.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/31/17. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation diff --git a/SoftU2FTool/WebSafeBase64.swift b/SoftU2FTool/WebSafeBase64.swift index 5f92c55..8b68693 100644 --- a/SoftU2FTool/WebSafeBase64.swift +++ b/SoftU2FTool/WebSafeBase64.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 9/13/16. -// Copyright © 2017 GitHub. All rights reserved. // import Foundation diff --git a/SoftU2FToolTests/IntegrationTests.swift b/SoftU2FToolTests/IntegrationTests.swift index a71acaf..2138219 100644 --- a/SoftU2FToolTests/IntegrationTests.swift +++ b/SoftU2FToolTests/IntegrationTests.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/27/17. -// Copyright © 2017 GitHub. All rights reserved. // import XCTest diff --git a/SoftU2FToolTests/SHA256Tests.swift b/SoftU2FToolTests/SHA256Tests.swift index 023a09b..5e9ea29 100644 --- a/SoftU2FToolTests/SHA256Tests.swift +++ b/SoftU2FToolTests/SHA256Tests.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 9/10/16. -// Copyright © 2017 GitHub. All rights reserved. // import XCTest diff --git a/SoftU2FToolTests/SoftU2FTestCase.swift b/SoftU2FToolTests/SoftU2FTestCase.swift index cb8adf2..12fac9c 100644 --- a/SoftU2FToolTests/SoftU2FTestCase.swift +++ b/SoftU2FToolTests/SoftU2FTestCase.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/30/17. -// Copyright © 2017 GitHub. All rights reserved. // import XCTest diff --git a/SoftU2FToolTests/TestUtil.swift b/SoftU2FToolTests/TestUtil.swift index 01dd5a7..f45f503 100644 --- a/SoftU2FToolTests/TestUtil.swift +++ b/SoftU2FToolTests/TestUtil.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 9/10/16. -// Copyright © 2017 GitHub. All rights reserved. // import XCTest diff --git a/SoftU2FToolTests/U2FHIDTests.swift b/SoftU2FToolTests/U2FHIDTests.swift index 418669f..9e84b6a 100644 --- a/SoftU2FToolTests/U2FHIDTests.swift +++ b/SoftU2FToolTests/U2FHIDTests.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/25/17. -// Copyright © 2017 GitHub. All rights reserved. // import XCTest diff --git a/SoftU2FToolTests/U2FRegistrationTests.swift b/SoftU2FToolTests/U2FRegistrationTests.swift index 1a52de7..75d21c4 100644 --- a/SoftU2FToolTests/U2FRegistrationTests.swift +++ b/SoftU2FToolTests/U2FRegistrationTests.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 1/31/17. -// Copyright © 2017 GitHub. All rights reserved. // import XCTest diff --git a/SoftU2FToolTests/UtilsTests.swift b/SoftU2FToolTests/UtilsTests.swift index a75d79a..a92d530 100644 --- a/SoftU2FToolTests/UtilsTests.swift +++ b/SoftU2FToolTests/UtilsTests.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 2/1/17. -// Copyright © 2017 GitHub. All rights reserved. // import XCTest diff --git a/SoftU2FToolTests/WebSafeBase64Tests.swift b/SoftU2FToolTests/WebSafeBase64Tests.swift index d4dee72..a9b0c91 100644 --- a/SoftU2FToolTests/WebSafeBase64Tests.swift +++ b/SoftU2FToolTests/WebSafeBase64Tests.swift @@ -3,7 +3,6 @@ // SoftU2F // // Created by Benjamin P Toews on 9/13/16. -// Copyright © 2017 GitHub. All rights reserved. // import XCTest