tclink 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +504 -0
- data/README +69 -0
- data/Rakefile +21 -0
- data/doc/TCDevGuide.html +1923 -0
- data/doc/TCDevGuide.txt +2160 -0
- data/ext/config.h +2 -0
- data/ext/extconf.rb +53 -0
- data/ext/mem.c +166 -0
- data/ext/rb_tclink.c +84 -0
- data/ext/tclink.c +1018 -0
- data/ext/tclink.h +83 -0
- data/ext/validate.c +154 -0
- data/tclink.gemspec +33 -0
- data/test/tclink_test.rb +36 -0
- metadata +59 -0
data/ext/tclink.h
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
/* tclink.h - Header file for TCLink library.
|
2
|
+
*
|
3
|
+
* TCLink Copyright (c) 2013 TrustCommerce.
|
4
|
+
* http://www.trustcommerce.com
|
5
|
+
* techsupport@trustcommerce.com
|
6
|
+
* (949) 387-3747
|
7
|
+
*
|
8
|
+
* This library is free software; you can redistribute it and/or
|
9
|
+
* modify it under the terms of the GNU Lesser General Public
|
10
|
+
* License as published by the Free Software Foundation; either
|
11
|
+
* version 2.1 of the License, or (at your option) any later version.
|
12
|
+
*
|
13
|
+
* This library is distributed in the hope that it will be useful,
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
16
|
+
* Lesser General Public License for more details.
|
17
|
+
*
|
18
|
+
* You should have received a copy of the GNU Lesser General Public
|
19
|
+
* License along with this library; if not, write to the Free Software
|
20
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
21
|
+
*/
|
22
|
+
|
23
|
+
#ifndef _TCLINK_H
|
24
|
+
#define _TCLINK_H
|
25
|
+
|
26
|
+
#include "config.h"
|
27
|
+
|
28
|
+
/* Handle passed to all TCLink functions. A unique handle must be created
|
29
|
+
* for each concurrent thread, but the same handle can be shared by transactions
|
30
|
+
* occurring one after another (such as a for loop).
|
31
|
+
*/
|
32
|
+
#define TCLinkHandle void *
|
33
|
+
|
34
|
+
/* Parameter names and values cannot exceed this size.
|
35
|
+
*/
|
36
|
+
#define PARAM_MAX_LEN 256
|
37
|
+
|
38
|
+
/* Create a new TCLinkHandle.
|
39
|
+
*/
|
40
|
+
TCLinkHandle TCLinkCreate();
|
41
|
+
|
42
|
+
/* Add a parameter to be sent to the server.
|
43
|
+
*/
|
44
|
+
void TCLinkPushParam(TCLinkHandle handle, const char *name, const char *value);
|
45
|
+
|
46
|
+
/* Flush the parameters to the server.
|
47
|
+
*/
|
48
|
+
void TCLinkSend(TCLinkHandle handle);
|
49
|
+
|
50
|
+
/* Look up a response value from the server.
|
51
|
+
* Returns NULL if no such parameter, or stores the value in 'value' and
|
52
|
+
* returns a pointer to value. value should be at least PARAM_MAX_LEN in size.
|
53
|
+
*/
|
54
|
+
char *TCLinkGetResponse(TCLinkHandle handle, const char *name, char *value);
|
55
|
+
|
56
|
+
/* Get all response values from the server in one giant string.
|
57
|
+
* Stores the string into buf and returns a pointer to it. Size should be
|
58
|
+
* sizeof(buf), which will limit the string so that no buffer overruns occur.
|
59
|
+
*/
|
60
|
+
char *TCLinkGetEntireResponse(TCLinkHandle handle, char *buf, int size);
|
61
|
+
|
62
|
+
/* Destory a handle, ending that transaction and freeing the memory associated with it. */
|
63
|
+
void TCLinkDestroy(TCLinkHandle handle);
|
64
|
+
|
65
|
+
/* Store version string into buf. Returns a pointer to buf. */
|
66
|
+
char *TCLinkGetVersion(char *buf);
|
67
|
+
|
68
|
+
|
69
|
+
/* The API methods below are subject to change. */
|
70
|
+
|
71
|
+
/* Enables (1) or Disables (0) the full SSL close_notify sequence. By default, this is set to 1.*/
|
72
|
+
int TCLinkSetFullClose(TCLinkHandle handle, int full_ssl_close);
|
73
|
+
|
74
|
+
/* Provides a method, before the first send call is initiated, of loading a set of trusted CA certificates (PEM format). */
|
75
|
+
void TCLinkSetTrustedCABundle(TCLinkHandle handle, const char *str, int len);
|
76
|
+
|
77
|
+
/* Provides a method, once the handshake is completed, a means to verify the contents of that certificate independently.
|
78
|
+
* Note that the certificate may not be set depending on the negotation type (in which case the pointer would be NULL)
|
79
|
+
*/
|
80
|
+
void TCLinkSetValidateCallback(TCLinkHandle handle, int (*validate_cert)(int, void *));
|
81
|
+
|
82
|
+
#endif
|
83
|
+
|
data/ext/validate.c
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
/*
|
2
|
+
COPYRIGHT AND PERMISSION NOTICE
|
3
|
+
|
4
|
+
Copyright (c) 1996 - 2010, Daniel Stenberg, <daniel@haxx.se>.
|
5
|
+
|
6
|
+
All rights reserved.
|
7
|
+
|
8
|
+
Permission to use, copy, modify, and distribute this software for any purpose
|
9
|
+
with or without fee is hereby granted, provided that the above copyright
|
10
|
+
notice and this permission notice appear in all copies.
|
11
|
+
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
13
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
14
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN
|
15
|
+
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
16
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
17
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
18
|
+
OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
Except as contained in this notice, the name of a copyright holder shall not
|
21
|
+
be used in advertising or otherwise to promote the sale, use or other dealings
|
22
|
+
in this Software without prior written authorization of the copyright holder.
|
23
|
+
*/
|
24
|
+
/* simplified to a basic host name check */
|
25
|
+
#include <string.h>
|
26
|
+
#include <openssl/x509_vfy.h>
|
27
|
+
#include <openssl/x509v3.h>
|
28
|
+
|
29
|
+
#define bool int
|
30
|
+
#define false 0
|
31
|
+
#define true 1
|
32
|
+
/** @fn static bool cert_hostcheck(const char *hostname, char *pattern)
|
33
|
+
* Verifies that the hostname matches against the pattern specified.
|
34
|
+
* Handles wildcard patterns and ignores the distinction between upper and lower case letters.
|
35
|
+
* Note: Ported over from ssluse.c in curl (7.1.16) lib
|
36
|
+
* Note: Explicit pattern match disabled as we do not use that for processing node certificate.
|
37
|
+
* Note: No longer ignores the distinction between upper and lower case letters. Our certificate is generated with lowercase letters.
|
38
|
+
* @return true if matches, false otherwise
|
39
|
+
* @param hostname The hostname we want to check. e.g: vault.trustcommerce.com
|
40
|
+
* @param pattern The pattern we wish to match against. e.g: *.trustcommerce.com
|
41
|
+
*/
|
42
|
+
bool cert_hostcheck(const char *pattern, const char *hostname)
|
43
|
+
{
|
44
|
+
if (!hostname || !pattern || !*hostname || !*pattern) return false;
|
45
|
+
if (!strcmp(hostname,pattern)) return true;
|
46
|
+
return false;
|
47
|
+
}
|
48
|
+
/** @fn static bool checkCertificate(X509 *cert, char *host)
|
49
|
+
* Provides validation of the hostname associated with a certificate.
|
50
|
+
* See RFC2818 - Server Identity for an overview of the concept.
|
51
|
+
* This implementation is based off the one found in curl-7.16.1: ssluse.c
|
52
|
+
* but we treat the subjectAltName as a recommendation... so if it fails,
|
53
|
+
* we will proceed to the CN check.
|
54
|
+
* The rationale for this is that we are not always using HTTP (over SSL)
|
55
|
+
* and its more of a certification generation / CA issue and we want
|
56
|
+
* maximum interoperability (as opposed to strict compliance).
|
57
|
+
* @param cert The X509 certificate in question.
|
58
|
+
* @param host The hostname or ip we wish to check.
|
59
|
+
* @return true if matches, false otherwise
|
60
|
+
*/
|
61
|
+
static bool checkCertificate(X509 * cert, const char *host)
|
62
|
+
{
|
63
|
+
int i,j;
|
64
|
+
bool matched = false;
|
65
|
+
STACK_OF(GENERAL_NAME) * altnames;
|
66
|
+
unsigned char *nulstr = { '\0' };
|
67
|
+
unsigned char *peer_CN = nulstr;
|
68
|
+
X509_NAME *name;
|
69
|
+
ASN1_STRING * tmp;
|
70
|
+
bool status = false;
|
71
|
+
|
72
|
+
if (!cert || !host) return false;
|
73
|
+
|
74
|
+
altnames = (STACK_OF(GENERAL_NAME) *)(X509_get_ext_d2i(cert, NID_subject_alt_name, NULL, NULL));
|
75
|
+
|
76
|
+
if (altnames != NULL)
|
77
|
+
{
|
78
|
+
int numalts = sk_GENERAL_NAME_num(altnames);
|
79
|
+
for (i=0; (i<numalts) && (matched == false); i++)
|
80
|
+
{
|
81
|
+
const GENERAL_NAME *check = sk_GENERAL_NAME_value(altnames, i);
|
82
|
+
const char *altptr = (char *)(ASN1_STRING_data(check->d.ia5));
|
83
|
+
size_t altlen;
|
84
|
+
switch (check->type)
|
85
|
+
{
|
86
|
+
case GEN_DNS:
|
87
|
+
altlen = ASN1_STRING_length(check->d.ia5);
|
88
|
+
if (altlen == strlen(host) && cert_hostcheck(altptr, host))
|
89
|
+
matched = true;
|
90
|
+
break;
|
91
|
+
case GEN_IPADD:
|
92
|
+
altlen = ASN1_STRING_length(check->d.ia5);
|
93
|
+
if (altlen == strlen(host) && !memcmp(altptr, host, altlen))
|
94
|
+
matched = true;
|
95
|
+
break;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
GENERAL_NAMES_free(altnames);
|
99
|
+
if (matched != false) return true;
|
100
|
+
}
|
101
|
+
|
102
|
+
i = j = -1;
|
103
|
+
|
104
|
+
|
105
|
+
name = X509_get_subject_name(cert);
|
106
|
+
if (!name) return false;
|
107
|
+
|
108
|
+
|
109
|
+
// get the last CN found in the subject (supposedly its the most distinguished one)
|
110
|
+
while ((j=X509_NAME_get_index_by_NID(name,NID_commonName,i))>=0)
|
111
|
+
i=j;
|
112
|
+
|
113
|
+
if (i<0) return false;
|
114
|
+
|
115
|
+
tmp = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name, i));
|
116
|
+
/* workaround for version of openssl < 0.9.7d */
|
117
|
+
if (tmp && ASN1_STRING_type(tmp) == V_ASN1_UTF8STRING)
|
118
|
+
{
|
119
|
+
j = ASN1_STRING_length(tmp);
|
120
|
+
if (j >= 0) {
|
121
|
+
peer_CN = (unsigned char *)(OPENSSL_malloc(j+1));
|
122
|
+
if (peer_CN)
|
123
|
+
{
|
124
|
+
memcpy(peer_CN, ASN1_STRING_data(tmp), j);
|
125
|
+
peer_CN[j] = '\0';
|
126
|
+
}
|
127
|
+
}
|
128
|
+
}
|
129
|
+
else
|
130
|
+
{
|
131
|
+
j = ASN1_STRING_to_UTF8(&peer_CN, tmp);
|
132
|
+
}
|
133
|
+
|
134
|
+
if (peer_CN == nulstr)
|
135
|
+
peer_CN = NULL;
|
136
|
+
|
137
|
+
if (peer_CN == NULL)
|
138
|
+
return false; // the cn isnt missing in virtually all cases
|
139
|
+
else if(!cert_hostcheck((char *)(peer_CN), host))
|
140
|
+
status = false;
|
141
|
+
else
|
142
|
+
status = true;
|
143
|
+
|
144
|
+
if (peer_CN)
|
145
|
+
OPENSSL_free(peer_CN);
|
146
|
+
return status;
|
147
|
+
}
|
148
|
+
|
149
|
+
int TCLinkDefaultValidate(int x, void * cert)
|
150
|
+
{
|
151
|
+
if (x != 0 || cert == NULL) return 0;
|
152
|
+
return !checkCertificate((X509 *)cert, "pgw1.trustcommerce.com");
|
153
|
+
|
154
|
+
}
|
data/tclink.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rubygems' unless defined?(Gem)
|
2
|
+
|
3
|
+
spec=Gem::Specification.new do |s|
|
4
|
+
s.name = 'tclink'
|
5
|
+
#note: extconf takes version out of this file
|
6
|
+
s.version = '4.2.0'
|
7
|
+
s.summary = "TCLink Trust Commerce link"
|
8
|
+
s.description = "Trust Commerce connectivity layer"
|
9
|
+
s.homepage = "http://trustcommerce.com"
|
10
|
+
s.license = "LGPL-2.1"
|
11
|
+
s.require_path = 'ext'
|
12
|
+
s.required_ruby_version = '>=1.8.7'
|
13
|
+
# s.has_rdoc = false
|
14
|
+
s.author = "Josh Puetz"
|
15
|
+
s.email = "developer@trustcommerce.com"
|
16
|
+
s.extensions = ["ext/extconf.rb"]
|
17
|
+
|
18
|
+
s.files = Dir['ext/*.c'] + Dir['ext/*.h'] + Dir['ext/extconf.rb'] + %w[
|
19
|
+
LICENSE README doc/TCDevGuide.html doc/TCDevGuide.txt
|
20
|
+
test/tclink_test.rb
|
21
|
+
Rakefile
|
22
|
+
tclink.gemspec]
|
23
|
+
s.files
|
24
|
+
end
|
25
|
+
|
26
|
+
if $0 == __FILE__
|
27
|
+
#Gem::manage_gems
|
28
|
+
#Gem::Builder.new(spec).build
|
29
|
+
require 'rubygems/gem_runner'
|
30
|
+
Gem::GemRunner.new.run ['build', 'tclink.gemspec']
|
31
|
+
end
|
32
|
+
|
33
|
+
spec
|
data/test/tclink_test.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
class TCLinkTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
# Called before every test method runs. Can be used
|
6
|
+
# to set up fixture information.
|
7
|
+
def setup
|
8
|
+
require_relative '../ext/tclink'
|
9
|
+
end
|
10
|
+
|
11
|
+
# Called after every test method runs. Can be used to tear
|
12
|
+
# down fixture information.
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
# Do nothing
|
16
|
+
end
|
17
|
+
|
18
|
+
# Fake test
|
19
|
+
def test_send
|
20
|
+
params = {}
|
21
|
+
params["custid"] = "TestMerchant"
|
22
|
+
params["password"] = "password"
|
23
|
+
params["action"] = "sale"
|
24
|
+
params["media"] = "cc"
|
25
|
+
params["cc"] = "4111111111111111"
|
26
|
+
params["exp"] = "0110"
|
27
|
+
params["amount"] = "100"
|
28
|
+
params["name"] = "Joe Ruby"
|
29
|
+
|
30
|
+
# Send the hash to TrustCommerce for processing
|
31
|
+
result = TCLink.send(params)
|
32
|
+
assert('approved').equal?(result['status'])
|
33
|
+
|
34
|
+
# fail('Not implemented')
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tclink
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 4.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Josh Puetz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Trust Commerce connectivity layer
|
14
|
+
email: developer@trustcommerce.com
|
15
|
+
executables: []
|
16
|
+
extensions:
|
17
|
+
- ext/extconf.rb
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- LICENSE
|
21
|
+
- README
|
22
|
+
- Rakefile
|
23
|
+
- doc/TCDevGuide.html
|
24
|
+
- doc/TCDevGuide.txt
|
25
|
+
- ext/config.h
|
26
|
+
- ext/extconf.rb
|
27
|
+
- ext/mem.c
|
28
|
+
- ext/rb_tclink.c
|
29
|
+
- ext/tclink.c
|
30
|
+
- ext/tclink.h
|
31
|
+
- ext/validate.c
|
32
|
+
- tclink.gemspec
|
33
|
+
- test/tclink_test.rb
|
34
|
+
homepage: http://trustcommerce.com
|
35
|
+
licenses:
|
36
|
+
- LGPL-2.1
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- ext
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.8.7
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 2.5.1
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: TCLink Trust Commerce link
|
58
|
+
test_files: []
|
59
|
+
has_rdoc:
|