beebtotp - GitHub 2fa for the BBC Master

handy tools that can assist in the development of new software
Post Reply
User avatar
ctr
Posts: 259
Joined: Wed Jul 16, 2014 3:53 pm
Contact:

beebtotp - GitHub 2fa for the BBC Master

Post by ctr »

With the Stardot GitHub requiring 2fa it seemed natural to create an implementation for the beeb. It needs a Master because the authentication codes are based on the current time.

I've attached an .ssd. Instructions and code are here.

It produces the same authentication codes as 2fa, but I wouldn't rely on it! Not without something better tested (like 2fa) as a backup anyway.

It presently only handles dates up to 2029 to work around a beebem bug. Coincidentally, Chris fixed this a couple of weeks ago so the workaround is only temporary.

I'd be interested to know if it works on a real Master.
Attachments
totp.ssd
(3.25 KiB) Downloaded 25 times
User avatar
ctr
Posts: 259
Joined: Wed Jul 16, 2014 3:53 pm
Contact:

Re: beebtotp - GitHub 2fa for the BBC Master

Post by ctr »

Cheers.

There's no better way to find bugs than to publish something. The Master clock reports local time but the calculation requires UTC, so it works here and now but won't work in other times and places.

You can set your Master clock to UTC or I could add a configurable timezone offset (which would need configuring twice a year) or a separate TOTPBST command for the summer (so you'd have to pick the right one each time you ran it) or automatic handling of summer time (maybe with different builds for non-UK timezones).
User avatar
BeebMaster
Posts: 7379
Joined: Sun Aug 02, 2009 5:59 pm
Location: Lost in the BeebVault!
Contact:

Re: beebtotp - GitHub 2fa for the BBC Master

Post by BeebMaster »

I don't know if it helps, but my BBC BASIC HTML Generator takes the TIME$ format of the BBC Master (copied into T$) and converts it to a 5-byte number representing the number of centiseconds since 1st January 1900, which is the format of RISC OS timestamps. If there is no TIME$ variable then it attempts to read the time from the current Econet fileserver, and then converts that to a TIME$ style string, also working out the day of the week, which isn't held in the Econet server time. It can cope with leap years and British Summer Time:

Code: Select all

    5*KEY0REPORT|M*FX0|MP.TIME$|MP.T$'S$'~?dblk,~dblk?1,~dblk?2,~dblk?3,~dblk?4|M
  450DIMptyp$(1),months 12,dblk 5,W%48,V%32,osb%64
  500ptyp$(0)="jpg":ptyp$(1)="png"
  550FORB%=1TO12:READmonths?B%:NEXT
  600DATA31,28,31,30,31,30,31,31,30,31,30,31
  650M$="JanFebMarAprMayJunJulAugSepOctNovDec"
 1450T$=STRING$(24," "):T$=""
 1500ONERROR GOTO1600
 1550T$=TIME$:IFMID$(T$,12,2)="19" T$=LEFT$(T$,11)+"20"+MID$(T$,14)
 1600ONERROR OFF
 1625IFT$=""T$=FNfstime:REM Get from FS if no RTC
 1627PROCconv:REM Convert string to RO date format
 1630IFLEFT$(T$,1)=" " T$=MID$(T$,5)
 1640END
14350DEFPROCconv
14400REM from T$ to csec since 1/1/1900
14450day=VAL(MID$(T$,5,2))
14500mn%=(INSTR(M$,MID$(T$,8,3))+2)/3
14550ye%=0:IFMID$(T$,12,2)="19"ye%=100:REM Cope with BASIC IV TIME$
14600ye%=ye%+VAL(MID$(T$,12,4))
14650ho%=VAL(MID$(T$,17,2))
14700min=VAL(MID$(T$,20,2))
14750sec=VAL(MID$(T$,23,2))
14800date=(ye%-1900)*365
14850date=date+((ye%-1901)DIV4)
14900IFmn%>1 FORB%=1TOmn%-1:date=date+(months?B%):NEXT
14950IF(ye%MOD 4)=0 ANDmn%>2 date=date+1
15000date=date+day-1
15050date=date*8640000
15100time=(ho%*360000)
15150time=time+(min*6000)
15200time=time+(sec*100)
15250date=date+time
15260IFFNbst(day,mn%,ye%) date=date-360000:REM deduct 1hr if BST
15300dblk?4=(date/2^32) MOD 256
15350dblk?3=(date/2^24) MOD 256
15400dblk?2=(date/2^16) MOD 256
15450dblk?1=(date/2^8) MOD 256
15500dblk?0=time MOD256
15550S$=""
15600FORC%=4TO0STEP-1
15650IFLENSTR$~dblk?C%=1 S$=S$+"0"
15700S$=S$+STR$~dblk?C%
15750NEXT
15800S$=" "+RIGHT$(S$,8)+" FFFFAF"+LEFT$(S$,2)
15850ENDPROC
25000DEFFNfstime
26000o%=1981
26010r%=FNosw(25,0,0,0,0)
26020REM L4 FS returns wrong yr by 28 yrs
26030IFosb%?4=ASC"4" l4%=TRUE ELSE l4%=FALSE
26040r%=FNosw(16,0,0,0,0)
26050IFr% PRINT"FS Error ";r%;": ";$(osb%+4)
26060hr%=osb%?6:mi%=osb%?7:sec%=osb%?8:dt%=osb%?5*256+osb%?4
26100REM FS date is 16bit no.:
26110 REM MSB > > > LSB
26120REM Y3Y2Y1Y0M3M2M1M0Y6Y5Y4D4D3D2D1D0
26130dy%=dt%AND31:mo%=(dt%AND&F00)DIV256:yr%=(dt%AND&F000)DIV4096+(dt%AND&E0)/2+o%:IFyr%>2000 AND l4% THEN yr%=yr%-28
26175=FNday(dy%,mo%,yr%)+","+STRING$(2-LENSTR$dy%,"0")+STR$dy%+" "+MID$(M$,(mo%-1)*3+1,3)+" "+STR$yr%+"."+STRING$(2-LENSTR$hr%,"0")+STR$hr%+":"+STRING$(2-LENSTR$mi%,"0")+STR$mi%+":"+STRING$(2-LENSTR$sec%,"0")+STR$sec%
26180DEFFNosw(op,h,m,s,d)
26200REM op=&10 rd, &1C wr
26210A%=&14:X%=osb%MOD256:Y%=osb%DIV256:!osb%=0:osb%?1=7:osb%?3=op:osb%!4=0:osb%?7=d MOD256:osb%?8=d DIV256:osb%?9=h:osb%?10=m:osb%?11=s
26330CALL&FFF1
26340=osb%?3
26650DEFFNday(dd%,mm%,yy%)
26660REM Method from thecompartments.uk
26670dw%=dd%
26680dw%=dw%+VALRIGHT$(STR$yy%,2)
26690dw%=dw%+VALRIGHT$(STR$yy%,2)/4
26700dw%=dw%+VAL(MID$("033614625035",mm%,1))
26710IFFNleap(yy%) AND mm%<3 dw%=dw%-1
26720dw%=dw%+VAL(MID$("0642",VAL(LEFT$(STR$yy%,2))MOD4+1,1))
26730dw%=dw% MOD7
26740=MID$("SatSunMonTueWedThuFri",(dw%*3)+1,3)
26750DEFFNleap(yy%)
26760IFyy% MOD4=0 ELSE =FALSE
26770IFyy% MOD100=0 THEN IF yy% MOD400=0 =TRUE
26780IFyy% MOD100=0 =FALSE
26790=TRUE
26800DEFFNbst(d%,m%,y%)
26810REM Is date BST?
26820REM 2 hr inaccuracy on last Sun in Mar & Oct!
26830IFm%>3 AND m%<10 =TRUE
26840IFm%=3 THEN ls%=32:REPEATls%=ls%-1:UNTILFNday(ls%,3,y%)="Sun":IFd%>=ls% THEN =TRUE
26850IFm%=10 THEN ls%=32:REPEATls%=ls%-1:UNTILFNday(ls%,10,y%)="Sun":IFd%<ls% THEN =TRUE
26860=FALSE
(n.b. not all the DIMs at line 450 are are used in the extract.

The S$ bit in DEFPROCconv builds load & exec addresses incorporating the RISC OS time-stamp it calculates, and the RISC OS filetype for HTML. I did that so I could use it on BBC BASIC on any Acorn without having to have a *SETTYPE command available.)

Works on Master 128:
Screenshot 2023-01-22 16-43-55.png
And BBC B reading time from Econet file server:
Screenshot 2023-01-22 16-47-22.png
Image
guesser
Posts: 708
Joined: Mon Jun 26, 2006 10:21 pm
Contact:

Re: beebtotp - GitHub 2fa for the BBC Master

Post by guesser »

Since we're already well down the road of pointlessness, you could read the Modified Julian date, and UTC timestamp from a Teletext Service Data Packet :lol:
Various teletext things including a web based teletext editor which can export as mode 7 screens.
Join the Teletext Discord for teletext chat.
User avatar
jgharston
Posts: 5321
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: beebtotp - GitHub 2fa for the BBC Master

Post by jgharston »

ctr wrote: Wed Jan 18, 2023 9:23 pm With the Stardot GitHub requiring 2fa it seemed natural to create an implementation for the beeb. It needs a Master a real-time clock because the authentication codes are based on the current time.
FTFY.

Code: Select all

>*FX0

OS 1.20
>*TIME
Sun,20 Jan 2023.20:01:45
>

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.45
(C) Copyright J.G.Harston 1989,2005-2024
>_
User avatar
jgharston
Posts: 5321
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: beebtotp - GitHub 2fa for the BBC Master

Post by jgharston »

BeebMaster wrote: Sun Jan 22, 2023 4:55 pm Works on Master 128:
(snip)
And BBC B reading time from Econet file server:
(snip)
...and a BBC reading from a RTC?

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.45
(C) Copyright J.G.Harston 1989,2005-2024
>_
User avatar
roland
Posts: 5148
Joined: Thu Aug 29, 2013 9:29 pm
Location: Born (NL)
Contact:

Re: beebtotp - GitHub 2fa for the BBC Master

Post by roland »

Timo can access a NTP server over the WiFi board to get the correct time :lol:
FPGAtom: 512 KB RAM, Real Time Clock and 64 colours
MAN WOMAN :shock:
User avatar
BeebMaster
Posts: 7379
Joined: Sun Aug 02, 2009 5:59 pm
Location: Lost in the BeebVault!
Contact:

Re: beebtotp - GitHub 2fa for the BBC Master

Post by BeebMaster »

jgharston wrote: Sun Jan 22, 2023 8:05 pm
BeebMaster wrote: Sun Jan 22, 2023 4:55 pm Works on Master 128:
(snip)
And BBC B reading time from Econet file server:
(snip)
...and a BBC reading from a RTC?
Yes, indeed, I accept that I should test for RTC availability (probably with OSWORD 14) rather than the availability of the TIME$ variable. Might do that in the next version.

And the other thing that happens is that if it gets to trying to read the network time, it falls over if there isn't a file server or Econet clock present, I've always found it difficult to trap errors when doing file server ops, as the OSWORD call dies with an error instead of returning a result code indicating an error.

Interestingly, when I tested what would happen when trying to read the file server time on a machine without Econet (which I did on Master 128 by *UNPLUGging ANFS) it put "FS Error 16" as part of the time string, so I've no idea how that could happen without any Econet firmware running!
Image
User avatar
BeebMaster
Posts: 7379
Joined: Sun Aug 02, 2009 5:59 pm
Location: Lost in the BeebVault!
Contact:

Re: beebtotp - GitHub 2fa for the BBC Master

Post by BeebMaster »

I've been making a new version of my HTML Generator today, so the first thing I did was to replace use of TIME$ with OSWORD 14, which will hopefully cater for the BBC-B-with-RTC situation, although it's not something I can test here, unless the PMS Genie Clock ROM I have supports OSWORD 14:

Code: Select all

 1450T$=STRING$(24," "):T$=""
 1500ONERROR GOTO1600
 1520A%=14:X%=W% MOD256:Y%=W% DIV256:?W%=0:CALL&FFF1
 1530REM n.b. result not CR'ed at byte 24 in 2P so need to truncate
 1550IF?W%=0 T$="" ELSET$=LEFT$($W%,24):IFMID$(T$,12,2)="19" T$=LEFT$(T$,11)+"20"+MID$(T$,14)
 1600ONERROR OFF
 1625IFT$=""T$=FNfstime:REM Get from FS if no RTC
I found that in the second processor (Pi Tube 6502 on Master 128) OSWORD 14 didn't terminate the string at the correct point, so rubbish was included after the time string unless I truncated the result to 24 bytes.
Image
User avatar
SKS1
Posts: 327
Joined: Sat Sep 19, 2020 12:04 am
Location: Highland Perthshire
Contact:

Re: beebtotp - GitHub 2fa for the BBC Master

Post by SKS1 »

"OSWORD 14 didn't terminate the string at the correct point"
Does Pi Tube have an option for 65C102? I'm sure I fixed that one for Tube OS 1.20 BITD
Miserable old curmudgeon who still likes a bit of an ARM wrestle now and then. Pi 4, 3, ARMX6, SA Risc PC, A540, A440
User avatar
hoglet
Posts: 12664
Joined: Sat Oct 13, 2012 7:21 pm
Location: Bristol
Contact:

Re: beebtotp - GitHub 2fa for the BBC Master

Post by hoglet »

SKS1 wrote: Mon Mar 20, 2023 6:30 pm "OSWORD 14 didn't terminate the string at the correct point"
Does Pi Tube have an option for 65C102? I'm sure I fixed that one for Tube OS 1.20 BITD
The lastest Hognose release has version 1.20 of the Tube ROM in all of the 6502 Co Pro flavours.

Dave
User avatar
BeebMaster
Posts: 7379
Joined: Sun Aug 02, 2009 5:59 pm
Location: Lost in the BeebVault!
Contact:

Re: beebtotp - GitHub 2fa for the BBC Master

Post by BeebMaster »

Yes, I think we discussed "problems with 6502 second processor and RTC" in some detail in a previous thread. The problem I had was with Tube Host 1.10 (in my PiTube Direct underneath Station 201, but it's wedged in but at a slightly jaunty angle and will either break the Pi or the motherboard connector if I try to remove it!)
Image
Post Reply

Return to “development tools”