forked from adamlaska/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit
More file actions
executable file
·69 lines (62 loc) · 2.31 KB
/
pre-commit
File metadata and controls
executable file
·69 lines (62 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
#
# $Id$
#
# Prevents some SHA-1 collisions to be commited
# Test fo the 320 byte prefix found on https://shattered.io/
# If the files are committed in the same transaction, svnlook
# will error out itself due to the apparent corruption in the
# candidate revision
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
YEAR=$(date +%Y)
$SVNLOOK changed -t "$TXN" "$REPOS"
if [ $? -ne 0 ]; then
echo "svnlook failed, possible SHA-1 collision" >&2
exit 2
fi
FILES=$($SVNLOOK changed -t "$TXN" "$REPOS" | grep -Ev '^D ' | /usr/bin/awk '{print $2}')
for FILE in $FILES; do
if [ -f $FILE ]; then
# Check against known sha-1 collision attack. Someone committing 2 different files with this
# known hash collision could otherwise break the repository.
PREFIX=$($SVNLOOK cat -t "$TXN" "$REPOS" "$FILE" | head -c320 | /usr/bin/sha1sum | cut -c-40)
if [ "$PREFIX" = 'f92d74e3874587aaf443d1db961d4e26dde13e9c' ]; then
echo "known SHA-1 collision rejected" >&2
exit 3
fi
# Verify copyright year
if [[ $FILE == */ietf/*.py || -s $FILE ]]; then
$SVNLOOK cat -t "$TXN" "$REPOS" "$FILE" | head -n 3 | grep -q "Copyright .*IETF Trust .*$YEAR.*" || {
echo "
Bad or missing copyright note in $FILE.
Expected 'Copyright The IETF Trust ... $YEAR, All Rights Reserved',
(or similar) at the start of the file.
For bulk correction of copyright statements, try bin/check-copyright with
patching:
\$ bin/check-copyright -p \$(svn st | cut -c 9- | grep '\.py\$' ) | patch -p0
" >&2
exit 3
}
fi
fi
done