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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
#!/usr/bin/env python
#
# 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.
#
"""
Send GPG-signed security advisory e-mails from an @apache.org address
to a known list of recipients, or write the advisory text in a form
suitable for publishing on http://subversion.apache.org/.
Usage: cd to the root directory of the advisory descriptions, then:
$ ${TRUNK_WC}/tools/dist/advisory.py send \
--username=<ASF-username> \
--revision=<dist-dev-revision-number>
--release-versions=<target-releases> \
--release-date=<expected-release-date> <CVE-number>...
or
$ ${TRUNK_WC}/tools/dist/advisory.py test \
(... --username, etc. as above)
or
$ ${TRUNK_WC}/tools/dist/advisory.py generate \
--destination=${SITE_WC}/publish/security \
<CVE-number>...
"""
from __future__ import absolute_import
import os
import sys
import argparse
import datetime
import getpass
import re
import security.parser
import security.adviser
import security.mailer
import security.mailinglist
ROOTDIR = os.path.abspath(os.getcwd())
NOTICE_TEMPLATE = 'notice-template.txt'
MAILING_LIST = 'pre-notifications.txt'
def parse_args(argv):
parser = argparse.ArgumentParser(
prog=os.path.basename(__file__), add_help=True,
description="""\
Send GPG-signed security advisory e-mails from an @apache.org address
to a known list of recipients, or write the advisory text in a form
suitable for publishing on http://subversion.apache.org/.
""")
parser.add_argument(
'command', action='store',
choices=['send', 'test', 'generate'],
help=('send: send mail; '
'test: write the mail to standard output; '
'generate: write an advisory for the website'))
parser.add_argument(
'--username', action='store', required=False,
help='the @apache.org username of the sender')
parser.add_argument(
'--revision', action='store', required=False, type=int,
help=('revision on dist.a.o./repos/dist/dev/subversion '
'in which the patched tarballs are available'))
parser.add_argument(
'--release-versions', action='store', required=False,
help=('comma-separated list of future released versions '
'that will contain the fix(es)'))
parser.add_argument(
'--release-date', action='store', required=False,
help=('expected release date for the above mentioned'
' versions (in ISO format, YYYY-MM-DD)'))
parser.add_argument(
'--destination', action='store', required=False,
help=('the directory where the website advisory should be '
'written; usually ${SITE_WC}/publish/security'))
parser.add_argument('cve', nargs='+')
return parser.parse_args(argv)
def check_root():
if not os.path.isfile(os.path.join(ROOTDIR, NOTICE_TEMPLATE)):
sys.stderr.write('Missing file: ' + NOTICE_TEMPLATE + '\n')
sys.exit(1)
if not os.path.isfile(os.path.join(ROOTDIR, MAILING_LIST)):
sys.stderr.write('Missing file: ' + MAILING_LIST + '\n')
sys.exit(1)
def check_sendmail(args):
if (not (args.username and args.revision
and args.release_versions
and args.release_date and args.cve)
or args.destination):
sys.stderr.write(
'The "' + args.command + '" command requires the '
'following options:\n'
' --username, --revision, --release-versions, --release-date\n'
' and a list of CVE numbers.\n')
sys.exit(1)
args.release_versions = re.split(r'\s*,\s*', args.release_versions)
args.release_date = datetime.datetime.strptime(args.release_date,
'%Y-%m-%d')
def sendmail(really_send, args):
notice_template = os.path.join(ROOTDIR, NOTICE_TEMPLATE)
mailing_list = os.path.join(ROOTDIR, MAILING_LIST)
sender = args.username + '@apache.org'
notification = security.parser.Notification(ROOTDIR, *args.cve)
mailer = security.mailer.Mailer(notification,
args.username + '@apache.org',
notice_template,
args.release_date,
args.revision,
*args.release_versions)
message = mailer.generate_message()
recipients = security.mailinglist.MailingList(mailing_list)
if (not really_send):
sys.stdout.write(message.as_string())
return
password = getpass.getpass('Password for ' + args.username
+ ' at mail-relay.apache.org: ')
mailer.send_mail(message, args.username, password,
recipients=recipients)
def check_generate(args):
if (not (args.destination and args.cve)
or args.username or args.revision
or args.release_versions
or args.release_date):
sys.stderr.write(
'The "generate" command requires the '
'--destination option '
'and a list of CVE numbers.\n')
sys.exit(1)
if not os.path.isdir(args.destination):
sys.stderr.write(args.destination + ' is not a directory')
sys.exit(1)
def generate(args):
notification = security.parser.Notification(ROOTDIR, *args.cve)
security.adviser.generate(notification, args.destination);
def main():
check_root()
args = parse_args(sys.argv[1:])
if args.command in ('send', 'test'):
check_sendmail(args)
sendmail(args.command == 'send', args)
elif args.command == 'generate':
check_generate(args)
generate(args)
if __name__ == '__main__':
main()
|