u2fhost 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 523083bccf9953e6ef6423ee772314a2d9b9291ef958fc03a5fc1474c68ff75c
4
+ data.tar.gz: ee83bcb3780b79a78010f9dc763626d9a03e201edb0af51f1d72aa2ce5a99141
5
+ SHA512:
6
+ metadata.gz: cf4ba5b42fb8d7d8a69574a6ab50887c0c04b4ce56a3530c4a84ef67fe00782525faf639f6140e064030a0ae733afb31f9f32fba44c077ad057e0b11475d8661
7
+ data.tar.gz: 5ab6f77518d0d146de20c86714b08e05cfc4e3f614a38a39331682c4528a170e219adaf591a361e44b842f328a6804b1c99706f3470fdad1369c6c338899bea1
@@ -0,0 +1,62 @@
1
+ FROM circleci/ruby:2.6.3-stretch
2
+ MAINTAINER Xaptum
3
+
4
+
5
+ LABEL version="1.0"
6
+ LABEL description="Base image for ruby-u2f-host build"
7
+
8
+ ENV U2F_HOST libu2f-host-1.1.10
9
+ ARG DEBIAN_FRONTEND=noninteractive
10
+
11
+ USER root
12
+
13
+ # make Apt non-interactive
14
+ RUN echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/90circleci \
15
+ && echo 'DPkg::Options "--force-confnew";' >> /etc/apt/apt.conf.d/90circleci \
16
+ && sed -i "s%{GPG_EXE}\")' --%{GPG_EXE}\")' --batch --%g" /usr/bin/apt-key
17
+
18
+ # Install dirmngr and gnugpg
19
+ RUN apt-get update && \
20
+ apt-get install -y --no-install-recommends \
21
+ gnupg \
22
+ dirmngr
23
+
24
+ # Install base packages
25
+ RUN apt-get update && \
26
+ apt-get install -y --no-install-recommends \
27
+ apt-utils \
28
+ xz-utils \
29
+ curl \
30
+ autoconf \
31
+ automake \
32
+ libtool \
33
+ pkg-config \
34
+ libjson-c-dev \
35
+ make \
36
+ libhidapi-hidraw0 \
37
+ g++ \
38
+ git \
39
+ libhidapi-dev && \
40
+ rm -rf /var/lib/apt/lists/*
41
+
42
+ # Install libu2f-host
43
+ ADD https://developers.yubico.com/libu2f-host/Releases/$U2F_HOST.tar.xz /root/
44
+ RUN tar -xvf /root/$U2F_HOST.tar.xz -C /root
45
+ WORKDIR /root/$U2F_HOST
46
+ RUN ./configure
47
+ RUN make check && make install
48
+
49
+ RUN gem install bundler
50
+ RUN gem install bump
51
+ RUN gem install geminabox
52
+ RUN gem install rufo
53
+
54
+ # Cleanup
55
+ RUN apt-get update && \
56
+ rm -rf /var/lib/apt/lists/* && \
57
+ rm -rf /root/$U2F_HOST && \
58
+ rm -rf /root/U2F_HOST.tar.xz
59
+
60
+ USER circleci
61
+ WORKDIR /home/circleci
62
+
@@ -0,0 +1,74 @@
1
+ #!/bin/bash
2
+
3
+ set -e
4
+
5
+ RELEASE_VSN_REGEX=[0-9]+.[0-9]+.[0-9]+$
6
+ PRE_VSN_REGEX=[0-9]+.[0-9]+.[0-9]+.pre.[a-z]+$
7
+
8
+ branch() {
9
+ # Check if branch name comes for drone
10
+ local BRANCH=${CIRCLE_BRANCH}
11
+
12
+ # Finally take from git
13
+ if [ "X$BRANCH" == X ]; then
14
+ BRANCH=$(git rev-parse --abbrev-ref HEAD)
15
+ fi
16
+ echo -n "${BRANCH}"
17
+ }
18
+
19
+ version() {
20
+ local VERSION=$(make version | sed -e 's/[cC]urrent [vV]ersion:\s*//')
21
+ echo -n "${VERSION}"
22
+ }
23
+
24
+ match() {
25
+ if [[ ! $1 =~ $2 ]]; then
26
+ exit -1
27
+ else
28
+ exit 0
29
+ fi
30
+ }
31
+
32
+ push_gem() {
33
+ local type=$1
34
+ local vsn=$2
35
+ local regex=$3
36
+
37
+ if [[ ${vsn} =~ ${regex} ]]; then
38
+ gem push pkg/u2fhost-${vsn}.gem
39
+ else
40
+ echo "Cannot publish ${type} for ${vsn}"
41
+ fi
42
+ }
43
+
44
+ deploy_gem() {
45
+ if [ "X${CIRCLE_TAG}" == X ]; then
46
+ # Tag is empty. Ensure pre-relase
47
+ local pre=$(version | sed -e 's/-/\.pre\./')
48
+ push_gem 'PRE-RELEASE' ${pre} ${PRE_VSN_REGEX}
49
+ else
50
+ local vsn=$(version)
51
+ push_gem 'RELEASE' ${vsn} ${RELEASE_VSN_REGEX}
52
+ fi
53
+ }
54
+
55
+ main() {
56
+ case $1 in
57
+ deploy)
58
+ if [ "X${CIRCLE_PROJECT_USERNAME}" == Xxaptum ]; then
59
+ deploy_gem
60
+ else
61
+ echo "Cannot deploy gem for ${CIRCLE_PROJECT_USERNAME}"
62
+ fi
63
+ ;;
64
+
65
+ *)
66
+ # Fail build
67
+ exit -1
68
+ ;;
69
+ esac
70
+ }
71
+
72
+ main $@
73
+
74
+
@@ -0,0 +1,108 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+
7
+ # aliases
8
+ release_steps: &release_steps
9
+ steps:
10
+ - checkout
11
+
12
+ - run:
13
+ name: install dependencies
14
+ command: |
15
+ make bundle
16
+
17
+ - run:
18
+ name: Setup Rubygems
19
+ command: |
20
+ .circleci/setup-rubygems.sh
21
+
22
+ - attach_workspace:
23
+ at: ~/u2fhost
24
+
25
+ - run:
26
+ name: deploy to rubygems
27
+ command: |
28
+ .circleci/build.sh deploy
29
+
30
+ # Jobs
31
+ jobs:
32
+ build:
33
+ docker:
34
+ # specify the version you desire here
35
+ - image: xaptumeng/u2fhost-build
36
+
37
+ working_directory: ~/u2fhost
38
+
39
+ steps:
40
+ - checkout
41
+
42
+ - run:
43
+ name: install dependencies
44
+ command: |
45
+ make bundle
46
+
47
+ - run:
48
+ name: Check code format
49
+ command: |
50
+ make check-format
51
+
52
+ - run:
53
+ name: build package
54
+ command: |
55
+ make build
56
+
57
+ # Perisist the gem to workspace
58
+ - persist_to_workspace:
59
+ root: ~/u2fhost
60
+ paths:
61
+ - pkg
62
+
63
+ # release job
64
+ release:
65
+ docker:
66
+ - image: xaptumeng/u2fhost-build
67
+
68
+ working_directory: ~/u2fhost
69
+ <<: *release_steps
70
+
71
+ # pre-release job
72
+ pre_release:
73
+ docker:
74
+ - image: xaptumeng/u2fhost-build
75
+
76
+ working_directory: ~/u2fhost
77
+ <<: *release_steps
78
+
79
+ # Workflows
80
+ workflows:
81
+ version: 2
82
+ u2fhost-workflow:
83
+ jobs:
84
+ - build:
85
+ context: gems.xaptum.xyz
86
+ filters:
87
+ branches:
88
+ only: /.*/
89
+ tags:
90
+ only: /^\d+\.\d+\.\d+$/
91
+
92
+ - release:
93
+ context: gems.xaptum.xyz
94
+ requires:
95
+ - build
96
+ filters:
97
+ branches:
98
+ ignore: /.*/
99
+ tags:
100
+ only: /^\d+\.\d+\.\d+$/
101
+
102
+ - pre_release:
103
+ context: gems.xaptum.xyz
104
+ requires:
105
+ - build
106
+ filters:
107
+ branches:
108
+ only: master
@@ -0,0 +1,3 @@
1
+ mkdir -p ~/.gem
2
+ echo -e "---\r\n:rubygems_api_key: $RUBYGEMS_API_KEY" > ~/.gem/credentials
3
+ chmod 0600 /home/circleci/.gem/credentials
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ *.so
13
+ *.bundle
14
+ *.dylib
15
+ .DS_Store
16
+ foo
17
+ bar
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in u2fhost.gemspec
4
+ gemspec
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ u2fhost (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ bump (0.10.0)
10
+ diff-lcs (1.4.4)
11
+ fuubar (2.5.0)
12
+ rspec-core (~> 3.0)
13
+ ruby-progressbar (~> 1.4)
14
+ rake (12.3.3)
15
+ rake-compiler (1.1.1)
16
+ rake
17
+ rspec (3.9.0)
18
+ rspec-core (~> 3.9.0)
19
+ rspec-expectations (~> 3.9.0)
20
+ rspec-mocks (~> 3.9.0)
21
+ rspec-core (3.9.3)
22
+ rspec-support (~> 3.9.3)
23
+ rspec-expectations (3.9.2)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.9.0)
26
+ rspec-mocks (3.9.1)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.9.0)
29
+ rspec-support (3.9.3)
30
+ rspec_junit_formatter (0.4.1)
31
+ rspec-core (>= 2, < 4, != 2.12.0)
32
+ ruby-progressbar (1.10.1)
33
+ rufo (0.12.0)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ bump
40
+ bundler
41
+ fuubar
42
+ rake
43
+ rake-compiler
44
+ rspec
45
+ rspec_junit_formatter
46
+ rufo
47
+ u2fhost!
48
+
49
+ BUNDLED WITH
50
+ 2.1.4
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2018 Xaptum, Inc
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,44 @@
1
+ .PHONY: bundle bump-patch bump-minor bump-major deploy test
2
+
3
+ build: compile
4
+ bundle exec rake build
5
+
6
+ compile:
7
+ bundle exec rake compile
8
+
9
+ console:
10
+ ./bin/console
11
+
12
+ bundle:
13
+ bundle install --jobs=4 --retry=3
14
+
15
+ bump-patch:
16
+ @bundle exec rake bump:patch TAG=false BUNDLE=false COMMIT=false
17
+
18
+ bump-minor:
19
+ @bundle exec rake bump:minor TAG=false BUNDLE=false COMMIT=false
20
+
21
+ bump-major:
22
+ @bundle exec rake bump:major TAG=false BUNDLE=false COMMIT=false
23
+
24
+ bump-pre:
25
+ @bundle exec rake bump:pre TAG=false BUNDLE=false COMMIT=false
26
+
27
+ version:
28
+ @bundle exec rake bump:current TAG=false BUNDLE=false COMMIT=false
29
+
30
+ #test:
31
+ # bundle exec rspec --format Fuubar --color spec/**/*_spec.rb
32
+
33
+ install: build
34
+ sudo ./install.sh
35
+
36
+ format:
37
+ ./format.sh
38
+
39
+ check-format:
40
+ @rufo --check lib
41
+ @rufo --check spec
42
+
43
+ clean:
44
+ rm -rf pkg
@@ -0,0 +1,163 @@
1
+ ## u2f-host-ruby
2
+ Ruby bindings for [libu2f-host](https://github.com/Yubico/libu2f-host) library. The `u2fhost` gem exposes two API's
3
+ - `register` Register using a U2F device
4
+ - `sign` Sign using a U2F device
5
+ This is similar to the API exposed by `u2f-api.js` javascript library.
6
+
7
+
8
+ ## Dependencies
9
+ Before installing this gem please install `libu2f-host` for you platform.
10
+
11
+ ### macos
12
+ ```bash
13
+ $ brew install libu2f-host
14
+ ```
15
+ If `Homebrew` throws any error stating unable to link some library, it may be necessary to explictly call
16
+ ```bash
17
+ $ brew link <libray name>
18
+ ```
19
+ Sometimes it may be necessary to change the ownership of `/usr/local/{lib,share,bin}` for the above commands to work.
20
+ ```bash
21
+ sudo chown -R `whoami`:admin /usr/local/bin
22
+ $ sudo chown -R `whoami`:admin /usr/local/lib
23
+ $ sudo chown -R `whoami`:admin /usr/local/share
24
+ ```
25
+
26
+ ### debian/ubuntu
27
+ ```bash
28
+ $ apt-get update
29
+ $ apt-get install libu2f-host-dev
30
+ ```
31
+
32
+ ### windows/other OS
33
+ Build from source following instructions in [libu2f-host](https://github.com/Yubico/libu2f-host) repository.
34
+
35
+
36
+ ## Installation
37
+ Add this line to your application's Gemfile:
38
+
39
+ ```ruby
40
+ gem 'u2fhost'
41
+ ```
42
+
43
+ And then execute:
44
+
45
+ $ bundle install
46
+
47
+ Or install it yourself as:
48
+
49
+ $ gem install u2fhost
50
+
51
+ ## Usage
52
+ Require the gem in your code
53
+ ```ruby
54
+ require 'u2fhost'
55
+ ```
56
+
57
+ ### Register
58
+ ```ruby
59
+ challenge = "..." ## challenge from server
60
+ origin = "..." ## U2F origin URL
61
+ response = U2fhost::register(challenge, origin)
62
+
63
+ ## send response to server to complete registration
64
+ ```
65
+
66
+ ### Sign
67
+ ```ruby
68
+ challenge = "..." ## challenge from server
69
+ origin = "..." ## U2F origin URL
70
+ response = U2fhost::sign(challenge, origin)
71
+
72
+ ## send response to server to verify signature
73
+ ```
74
+
75
+ The API's throw `U2fhost::ERROR` exception in case of any errors.
76
+
77
+
78
+ ## Development
79
+ - Ensure `bundler` gem is installed. If not, install using
80
+ ```
81
+ $ gem install bundler
82
+ ```
83
+ - Clone the repository
84
+ - Install dependent gems
85
+ ```
86
+ $ cd u2f-host-ruby
87
+ $ make bundle
88
+ ```
89
+
90
+ - Create a new branch
91
+ ```bash
92
+ git checkout -b <GIT_USER_NAME>/<BRANCH_NAME>
93
+ ```
94
+ - Bump the version
95
+ ```bash
96
+ make bump-pre
97
+ ```
98
+ - Ensure code is formatted using `rufo`. The build process will fail if the code is not formatted.
99
+ ```bash
100
+ make format
101
+ ```
102
+
103
+ **NOTE: Do not fork the repository**
104
+
105
+ ## Testing
106
+ As this gem interacts with a hardware device, any changes has to be tested manually. The project is setup to build and install the gem on the local machine.
107
+
108
+ - build the gem
109
+ ```bash
110
+ $ make build
111
+ ```
112
+ This will create the `u2fhost-VERSION.gem` file in `pkg` directory
113
+
114
+ - install gem
115
+ ```bash
116
+ $ make install
117
+ ```
118
+ This will install the gem on the local machine
119
+
120
+ - run the test executable
121
+ ```bash
122
+ $ bin/test
123
+ ```
124
+
125
+
126
+ Another way to test after installing the gem is to launch `irb`
127
+ ```bash
128
+ $ irb
129
+ irb(main):001:0> require 'u2fhost'
130
+ => true
131
+ irb(main):002:0>
132
+ ```
133
+
134
+ ## Release
135
+ `u2fhost` pre-release and release versions are automatically published to [RubyGems](https://rubygems.org) by the build process. Each commit to `master` branch publishes a pre-release version of the gem.
136
+
137
+ ### Publishing Pre-Release version
138
+ - Open a pull request to merge the feature branch into `master`
139
+ - After review and approval merge feature branch into `master`
140
+ - The build process publishes a pre-release version if gem version matches one of the following patterns:
141
+ - `MAJOR.MINOR.PATCH-alpha`
142
+ - `MAJOR.MINOR.PATCH-beta`
143
+ - `MAJOR.MINOR.PATCH-rc`
144
+
145
+ ### Publishing a Release version
146
+ - Update `u2fhost` version to `MAJOR.MINOR.PATCH` in `lib/u2fhost/version.rb` and commit the change to `master`
147
+ - Create and push a tag with the same name as the version
148
+ - The build process publishes a release version of the gem
149
+
150
+ # License
151
+ Copyright 2020 Xaptum, Inc.
152
+
153
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not
154
+ use this work except in compliance with the License. You may obtain a copy of
155
+ the License from the LICENSE.txt file or at
156
+
157
+ [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
158
+
159
+ Unless required by applicable law or agreed to in writing, software
160
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
161
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
162
+ License for the specific language governing permissions and limitations under
163
+ the License.
@@ -0,0 +1,27 @@
1
+ require "bundler/gem_tasks"
2
+ require "bump/tasks"
3
+ #require "rspec/core/rake_task"
4
+ require "rake/extensiontask"
5
+
6
+ #desc "Run tests"
7
+ #RSpec::Core::RakeTask.new(:spec) do |t|
8
+ # t.pattern = "spec/**/*_spec.rb"
9
+ # t.verbose = true
10
+ #end
11
+
12
+ Rake::ExtensionTask.new("u2fhost") do |ext|
13
+ ext.lib_dir = "lib/u2fhost"
14
+ end
15
+
16
+ #gemspec = Gem::Specification.load("u2fhost.gemspec")
17
+ #Rake::ExtensionTask.new do |ext|
18
+ # ext.name = "u2fhost"
19
+ # ext.source_pattern = "*.{c,h}"
20
+ # ext.ext_dir = "ext/u2fhost"
21
+ # ext.lib_dir = "lib/u2fhost"
22
+ # ext.gem_spec = gemspec
23
+ #end
24
+
25
+ #task :default => [:compile, :spec]
26
+
27
+ #task :default => [:spec]
@@ -0,0 +1,32 @@
1
+ #
2
+ # Copyright 2020 Xaptum,Inc
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ require "mkmf"
17
+
18
+ $LOCAL_LIBS << " -lu2f-host "
19
+ $INCFLAGS << " -I/usr/local/include/u2f-host -I/usr/include/u2f-host -I /opt/local/include/u2f-host "
20
+
21
+ #if RUBY_PLATFORM =~ /darwin/
22
+ # $LDFLAGS << "-framework AppKit"
23
+ #end
24
+
25
+ abort "missing u2fh_register2()" unless have_func "u2fh_register2"
26
+ abort "missing u2fh_authenticate2()" unless have_func "u2fh_authenticate2"
27
+
28
+ extension_name = "u2fhost"
29
+
30
+ dir_config(extension_name)
31
+ create_header
32
+ create_makefile(extension_name)
@@ -0,0 +1,146 @@
1
+ /*
2
+ * Copyright 2020 Xaptum,Inc
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ #include <ruby.h>
17
+ #include <math.h>
18
+ #include <u2f-host.h>
19
+
20
+ #define SYM_ERROR ID2SYM(rb_intern("error"))
21
+ #define SYM_RESPONSE ID2SYM(rb_intern("response"))
22
+
23
+ #define BUFFER_SIZE 8192
24
+
25
+ #define REGISTER 1
26
+ #define SIGN 2
27
+
28
+ // API function headers
29
+ static VALUE ext_register(VALUE self, VALUE rb_challenge, VALUE rb_origin);
30
+ static VALUE ext_sign(VALUE self, VALUE rb_challenge, VALUE rb_origin);
31
+
32
+ // helper functions
33
+ static VALUE make_hash(VALUE key, const char *value) {
34
+ VALUE hash = rb_hash_new();
35
+ rb_hash_aset(hash, key, rb_str_new2(value));
36
+ return hash;
37
+ }
38
+
39
+ static VALUE error_hash(const char *error) {
40
+ return make_hash(SYM_ERROR, error);
41
+ }
42
+
43
+ static VALUE response_hash(const char *resp) {
44
+ return make_hash(SYM_RESPONSE, resp);
45
+ }
46
+
47
+ // actual implementations
48
+ static VALUE do_u2f_action(VALUE self, VALUE rb_challenge, VALUE rb_origin, int action) {
49
+ VALUE retHash = Qnil;
50
+
51
+ char buffer[BUFFER_SIZE] = {0};
52
+ u2fh_devs *devs = NULL;
53
+ u2fh_rc rc;
54
+
55
+ char *challenge = NULL;
56
+ char *origin = NULL;
57
+
58
+ char response[BUFFER_SIZE] = {0};
59
+ size_t response_len = sizeof(response);
60
+
61
+ // validate args are in string type
62
+ Check_Type(rb_challenge, T_STRING);
63
+ Check_Type(rb_origin, T_STRING);
64
+
65
+ // convert ruby string to C string
66
+ challenge = StringValueCStr(rb_challenge);
67
+ origin = StringValueCStr(rb_origin);
68
+
69
+ // initialize u2f library
70
+ rc = u2fh_global_init(0);
71
+ if( U2FH_OK != rc ) {
72
+ sprintf(buffer, "error: u2fh_global_init (%d): %s\n", rc, u2fh_strerror (rc));
73
+ return error_hash(buffer);
74
+ }
75
+
76
+ // initialize u2f devices data structure
77
+ rc = u2fh_devs_init(&devs);
78
+ if (U2FH_OK != rc) {
79
+ sprintf(buffer, "error: u2fh_devs_init (%d): %s\n", rc, u2fh_strerror (rc));
80
+ retHash = error_hash(buffer);
81
+ goto cleanup;
82
+ }
83
+
84
+ // discover u2f devices
85
+ rc = u2fh_devs_discover(devs, NULL);
86
+ if (U2FH_OK != rc) {
87
+ sprintf(buffer, "error: u2fh_devs_discover (%d): %s\n", rc, u2fh_strerror (rc));
88
+ retHash = error_hash(buffer);
89
+ goto cleanup;
90
+ }
91
+
92
+ // register/sign
93
+ switch(action) {
94
+ case REGISTER:
95
+ rc = u2fh_register2(devs, challenge, origin,
96
+ response, &response_len,
97
+ U2FH_REQUEST_USER_PRESENCE);
98
+ break;
99
+
100
+ case SIGN:
101
+ rc = u2fh_authenticate2(devs, challenge, origin,
102
+ response, &response_len,
103
+ U2FH_REQUEST_USER_PRESENCE);
104
+
105
+ break;
106
+ }
107
+
108
+ // handle response
109
+ if (U2FH_OK != rc) {
110
+ sprintf(buffer, "error (%d): %s\n", rc, u2fh_strerror (rc));
111
+ retHash = error_hash(buffer);
112
+ goto cleanup;
113
+ }
114
+
115
+ // create response hash
116
+ retHash = response_hash(response);
117
+
118
+ cleanup:
119
+ u2fh_devs_done(devs);
120
+ u2fh_global_done();
121
+
122
+ // return appropriate hash
123
+ return retHash;
124
+ }
125
+
126
+ // register
127
+ static VALUE ext_register(VALUE self, VALUE rb_challenge, VALUE rb_origin) {
128
+ return do_u2f_action(self, rb_challenge, rb_origin, REGISTER);
129
+ }
130
+
131
+ // sign
132
+ static VALUE ext_sign(VALUE self, VALUE rb_challenge, VALUE rb_origin) {
133
+ return do_u2f_action(self, rb_challenge, rb_origin, SIGN);
134
+ }
135
+
136
+ // init
137
+ void Init_u2fhost() {
138
+ // create module
139
+ VALUE mod = rb_define_module("U2fhost");
140
+
141
+ // attach ext_register to the module
142
+ rb_define_singleton_method(mod, "ext_register", ext_register, 2);
143
+
144
+ // attach ext_sign to the module
145
+ rb_define_singleton_method(mod, "ext_sign", ext_sign, 2);
146
+ }
@@ -0,0 +1,9 @@
1
+ #!/bin/bash
2
+
3
+ ## Formatting is done using rufo library
4
+ ## rufo exits with exit code 3 if it is able to
5
+ ## format the code.
6
+
7
+ echo "Formatting code.."
8
+ rufo lib spec
9
+ echo "Formatted!"
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+
3
+ echo "Installing u2fhost gem locally"
4
+ version=$(make version)
5
+
6
+ ## Uninstall gem if necessary
7
+ gem uninstall u2fhost
8
+
9
+ ## install gem
10
+ gem install pkg/u2fhost-$version.gem
@@ -0,0 +1,49 @@
1
+ #
2
+ # Copyright 2020 Xaptum,Inc
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ require "u2fhost/version"
17
+ require "u2fhost.so"
18
+
19
+ module U2fhost
20
+ class ERROR < StandardError
21
+ def initialize(msg = "ENF Api Error")
22
+ super
23
+ end
24
+ end
25
+
26
+ ## register API
27
+ def self.register(challenge, origin)
28
+ ## call extenstion
29
+ call_ext_block { ext_register(challenge, origin) }
30
+ end
31
+
32
+ ## sign API
33
+ def self.sign(challenge, origin)
34
+ ## call extenstion
35
+ call_ext_block { ext_sign(challenge, origin) }
36
+ end
37
+
38
+ def self.call_ext_block
39
+ ## call extenstion
40
+ hash = yield
41
+
42
+ ## parse return value from the calling extenstion
43
+ ## raise exception if error response
44
+ raise U2fhost::ERROR, hash[:error] if hash[:error]
45
+
46
+ ## return response
47
+ hash[:response]
48
+ end
49
+ end
@@ -0,0 +1,18 @@
1
+ #
2
+ # Copyright 2020 Xaptum,Inc
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ module U2fhost
17
+ VERSION = "1.0.0"
18
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "u2fhost/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "u2fhost"
8
+ spec.version = U2fhost::VERSION
9
+ spec.authors = ["Venkatakumar Srinivasan", "Matthew Lee"]
10
+ spec.email = ["venkat@xaptum.com", "matthew.lee@xaptum.com"]
11
+
12
+ spec.summary = %q{Ruby bindings for libu2f-host}
13
+ spec.homepage = "https://www.xaptum.com"
14
+ spec.license = "Apache-2.0"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/xaptum/u2fhost"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.extensions << "ext/u2fhost/extconf.rb"
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "rake-compiler"
29
+ spec.add_development_dependency "bundler"
30
+ spec.add_development_dependency "rake"
31
+ spec.add_development_dependency "bump"
32
+ spec.add_development_dependency "rspec"
33
+ spec.add_development_dependency "rspec_junit_formatter"
34
+ spec.add_development_dependency "fuubar"
35
+ spec.add_development_dependency "rufo"
36
+ end
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: u2fhost
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Venkatakumar Srinivasan
8
+ - Matthew Lee
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2020-10-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake-compiler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: bump
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec_junit_formatter
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: fuubar
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: rufo
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description:
127
+ email:
128
+ - venkat@xaptum.com
129
+ - matthew.lee@xaptum.com
130
+ executables: []
131
+ extensions:
132
+ - ext/u2fhost/extconf.rb
133
+ extra_rdoc_files: []
134
+ files:
135
+ - ".circleci/Dockerfile"
136
+ - ".circleci/build.sh"
137
+ - ".circleci/config.yml"
138
+ - ".circleci/setup-rubygems.sh"
139
+ - ".gitignore"
140
+ - ".rspec"
141
+ - Gemfile
142
+ - Gemfile.lock
143
+ - LICENSE
144
+ - Makefile
145
+ - README.md
146
+ - Rakefile
147
+ - ext/u2fhost/extconf.rb
148
+ - ext/u2fhost/u2fhost.c
149
+ - format.sh
150
+ - install.sh
151
+ - lib/u2fhost.rb
152
+ - lib/u2fhost/version.rb
153
+ - u2fhost.gemspec
154
+ homepage: https://www.xaptum.com
155
+ licenses:
156
+ - Apache-2.0
157
+ metadata:
158
+ homepage_uri: https://www.xaptum.com
159
+ source_code_uri: https://github.com/xaptum/u2fhost
160
+ post_install_message:
161
+ rdoc_options: []
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: 2.3.0
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ requirements: []
175
+ rubygems_version: 3.0.3
176
+ signing_key:
177
+ specification_version: 4
178
+ summary: Ruby bindings for libu2f-host
179
+ test_files: []