Skip to content

Commit a33aab8

Browse files
committed
synchronize files with no-extension branch
1 parent c7c60f3 commit a33aab8

6 files changed

Lines changed: 91 additions & 36 deletions

File tree

u2f-gae-demo/src/com/google/u2f/gaedemo/admin/AdminServlet.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.google.template.soy.data.SoyMapData;
2222
import com.google.template.soy.tofu.SoyTofu;
2323
import com.google.template.soy.tofu.SoyTofu.Renderer;
24-
import com.google.u2f.gaedemo.storage.SecretKeys;
2524

2625
@SuppressWarnings("serial")
2726
@Singleton
@@ -57,17 +56,6 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
5756
throws ServletException, IOException {
5857

5958
String command = req.getParameter("command");
60-
61-
if ("generateKeys".equalsIgnoreCase(command)) {
62-
generateKeys(req, resp);
63-
} else {
64-
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "unknown command");
65-
}
66-
67-
}
68-
69-
private void generateKeys(HttpServletRequest req, HttpServletResponse resp) throws IOException {
70-
SecretKeys.generate();
71-
doGet(req, resp);
59+
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "unknown command: " + command);
7260
}
7361
}

u2f-gae-demo/src/com/google/u2f/gaedemo/storage/SecretKeys.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import java.security.SecureRandom;
1212

13-
import com.google.common.base.Objects;
13+
import com.googlecode.objectify.Work;
1414
import com.googlecode.objectify.annotation.Entity;
1515
import com.googlecode.objectify.annotation.Id;
1616
import com.googlecode.objectify.annotation.Ignore;
@@ -25,16 +25,32 @@ public class SecretKeys {
2525

2626
@Ignore private SecureRandom random = new SecureRandom();
2727

28-
public static void generate() {
29-
SecretKeys keys = Objects.firstNonNull(
30-
ofy().load().type(SecretKeys.class).id("singleton").now(),
31-
new SecretKeys());
32-
keys.generateNewKeys();
33-
ofy().save().entity(keys).now();
28+
private static SecretKeys generate() {
29+
return ofy().transact(new Work<SecretKeys>() {
30+
@Override
31+
public SecretKeys run() {
32+
SecretKeys keys = ofy().load().type(SecretKeys.class).id("singleton").now();
33+
if (keys != null) {
34+
return keys;
35+
} else {
36+
keys = new SecretKeys();
37+
keys.generateNewKeys();
38+
ofy().save().entity(keys).now();
39+
return keys;
40+
}
41+
}
42+
});
3443
}
3544

3645
public static SecretKeys get() {
37-
return ofy().load().type(SecretKeys.class).id("singleton").now();
46+
SecretKeys keys = ofy().load().type(SecretKeys.class).id("singleton").now();
47+
48+
if (keys == null) {
49+
// somebody (we?) need to generate the keys
50+
return generate();
51+
} else {
52+
return keys;
53+
}
3854
}
3955

4056
public SecretKeys() {

u2f-gae-demo/src/soy/admin.soy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
<body>
1818
{call .sandbar data="all"/}
1919
<div id='main'>
20-
<form action="/admin?command=generateKeys" method="POST">
21-
<input type="submit" value="Generate New Keys"></input>
20+
<!-- you can put commands here for admins to do -->
21+
<form action="/admin?command=someAdminCommand" method="POST">
2222
</form>
2323
</body>
2424
</html>

u2f-gae-demo/war/js/u2fdemo.js

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ function tokenToDom(token) {
2424
card.querySelector('.issuer').textContent = token.issuer;
2525
card.querySelector('.enrollmentTimeValue').textContent = timeString;
2626
if (token.transports == null || token.transports === undefined) {
27-
card.querySelector('.transportsValue').textContent = "None specified";
27+
card.querySelector('.transportsValue').textContent = "None specified";
2828
} else {
29-
card.querySelector('.transportsValue').textContent = token.transports;
29+
card.querySelector('.transportsValue').textContent = token.transports;
3030
}
3131
card.querySelector('.keyHandle').textContent = token.key_handle;
3232
card.querySelector('.publicKey').textContent = token.public_key;
@@ -70,10 +70,22 @@ function hideMessage() {
7070

7171
function highlightTokenCardOnPage(token) {
7272
console.log(token);
73-
var cardContent = $("#" + token.public_key).find(".cardContent");
74-
75-
cardContent.addClass("highlight");
76-
window.setTimeout(function() { cardContent.removeClass("highlight", 2000); }, 500 );
73+
74+
var cardChildren = document.getElementById(token.public_key).children;
75+
for (i = 0; i < cardChildren.length; i++) {
76+
if ($(cardChildren[i]).hasClass("cardContent")) {
77+
$(cardChildren[i]).addClass("highlight");
78+
}
79+
}
80+
81+
window.setTimeout(
82+
function() {
83+
for (i = 0; i < cardChildren.length; i++) {
84+
$(cardChildren[i]).removeClass("highlight", 2000);
85+
}
86+
},
87+
500
88+
);
7789
}
7890

7991

@@ -197,3 +209,40 @@ function onError(code, enrolling) {
197209
break;
198210
}
199211
}
212+
213+
if (navigator.userAgent.indexOf("iPhone") > -1) {
214+
function executeRequest (request) {
215+
var str = JSON.stringify(request);
216+
var url = "u2f://auth?" + encodeURI(str);
217+
location.replace(url);
218+
}
219+
220+
u2f.callbackMap_ = {};
221+
u2f.sign = function(signRequests, callback, opt_timeoutSeconds) {
222+
var reqId = ++u2f.reqCounter_;
223+
u2f.callbackMap_[reqId] = callback;
224+
var req = {
225+
type: u2f.MessageTypes.U2F_SIGN_REQUEST,
226+
signRequests: signRequests,
227+
timeoutSeconds: (typeof opt_timeoutSeconds !== 'undefined' ?
228+
opt_timeoutSeconds : u2f.EXTENSION_TIMEOUT_SEC),
229+
requestId: reqId
230+
};
231+
executeRequest(req);
232+
};
233+
234+
u2f.register = function(registerRequests, signRequests,
235+
callback, opt_timeoutSeconds) {
236+
var reqId = ++u2f.reqCounter_;
237+
u2f.callbackMap_[reqId] = callback;
238+
var req = {
239+
type: u2f.MessageTypes.U2F_REGISTER_REQUEST,
240+
signRequests: signRequests,
241+
registerRequests: registerRequests,
242+
timeoutSeconds: (typeof opt_timeoutSeconds !== 'undefined' ?
243+
opt_timeoutSeconds : u2f.EXTENSION_TIMEOUT_SEC),
244+
requestId: reqId
245+
};
246+
executeRequest(req);
247+
};
248+
}

u2f-ref-code/java/src/com/google/u2f/server/data/SecurityKeyData.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ public SecurityKeyData(
3939
}
4040

4141
public SecurityKeyData(
42-
long enrollmentTime,
43-
List<Transports> transports,
44-
byte[] keyHandle,
45-
byte[] publicKey,
46-
X509Certificate attestationCert,
47-
int counter) {
42+
long enrollmentTime,
43+
List<Transports> transports,
44+
byte[] keyHandle,
45+
byte[] publicKey,
46+
X509Certificate attestationCert,
47+
int counter) {
4848
this.enrollmentTime = enrollmentTime;
4949
this.transports = transports;
5050
this.keyHandle = keyHandle;

u2f-ref-code/java/src/com/google/u2f/server/impl/U2FServerReferenceImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.bouncycastle.asn1.DERBitString;
2727
import org.bouncycastle.asn1.DEROctetString;
2828

29+
import com.google.common.base.Joiner;
2930
import com.google.common.collect.ImmutableList;
3031
import com.google.common.collect.ImmutableSet;
3132
import com.google.gson.JsonElement;
@@ -409,7 +410,8 @@ private void verifyBrowserData(JsonElement browserDataAsElement,
409410
private void verifyOrigin(String origin) throws U2FException {
410411
if (!allowedOrigins.contains(canonicalizeOrigin(origin))) {
411412
throw new U2FException(origin +
412-
" is not a recognized home origin for this backend");
413+
" is not a recognized home origin for this backend" +
414+
Joiner.on(", ").join(allowedOrigins));
413415
}
414416
}
415417

0 commit comments

Comments
 (0)